c# 4.0 - @Url.action cast exception -
i trying implement @url.action on link clicked.
link = "@url.action("exportweeklytimesheetpdf", "hours", new { projectid = model.projectid, reporttype = 'week', reportdate = 'reportdate'})" link.replace("reportdate",datestring); $("#exportpdf").attr("href", link); when try add , reporttype = 'week', reportdate = 'reportdate' keep getting unhandled cast exception. if dont have reporttype , reportdate, working fine. how solve mess? appreciated.
thank nikhil
it seems you're trying assign return value of c# method javascript variable, replace part of javascript variable. correct me if i'm wrong.
you need take closer , work out you've written doing. won't work because you're using single quotes instead of double, , javascript link.replace line replace first instance of reportdate.
this code should work:
@{ string url = url.action("exportweeklytimesheetpdf", "hours", new { projectid = model.projectid, reporttype = "week", reportdate = "replacewithreportdate"}); } link = "@url"; link.replace("replacewithreportdate", datestring); $("#exportpdf").attr("href", link); you'll still need ensure replacewithreportdate changed in resulting link in expected format.
Comments
Post a Comment