c# - @Html.Action MVC 4 with QueryString Parameters -
i have question related html.action in mvc 4 want pass querystring variables details view
the code have
system.text.stringbuilder mobiledata = new system.text.stringbuilder(); mobiledata.appendformat("<a style=\"text-align:left;\" data-role=\"button\" onclick=\"window.location='" + @url.action("taken_detail", new { id = tk.id }) + "';\" data- ajax=\"true\" data-icon=\"alert\"><span class=\"agenitems\">{1:dd-mm-yyyy}</span>", tk.id, tk.datum);
the problem redirect me localhost/projectname/home/taken_detail/2 want home/taken_detail?id=2 missing here starting learn mvc 4, every tip welcome.
this because routes contain id
parameter. remove routes , url.action
change url , add parameter query string.
example:
routes.maproute("default", "{controller}/{action}/{id}", new { controller = "home", action = "index", id = urlparameter.optional });
the id
parameter put after last slash if specify url.action
.
if remove it:
routes.maproute("default", "{controller}/{action}", new { controller = "home", action = "index" });
the resulting url have query string containing id
.
Comments
Post a Comment