Reputation: 5126
I have a view file from where I am trying to send the url to the controller file My view file looks like:
@model WebRole1.Models.CodeSnippet
@{
ViewBag.Title = "Details";
}
<p>
@Html.ActionLink("Preview", "Preview", new { Model.URL }) |
</p>
In the above code I am trying to send the url value to the controller file. Function in the controller file looks like
public ActionResult Preview(object zipPath)
{
// some operation...
}
However for some reason view is sending null value to the controller. i.e. when Preview method of controller gets called zipPath
value remains null. What can be the issue?
Upvotes: 0
Views: 658
Reputation: 26635
Your action method is waiting for property with the name zipPath
. But, since you don't provide a name for a property in your anonymous object, it will be URL
by default.
So, change your code to:
@Html.ActionLink("Preview", "Preview", new { zipPath = Model.URL })
Additional information:
If you have included zipPath
as a URL segment in your route, then the value will assigned to this segment by the routing segment. Otherwise, the value we supplied will be added as part of the query string.
Upvotes: 6