Reputation: 21
I am new to ASP.net and MVC so forgive me if this seems like a silly question.
I have the following Actionlink:
<span>@Html.ActionLink(item.MetadataDocumentSetId.ToString(), "ShowDocumentMetadata", new { controller = "Metadata", id = item.MetadataDocumentSetId })</span>
I also have this (currently commented out):
<span>@Html.TextBoxFor(x => item.MetadataDocumentSetId, new { style = "display:inline"})</span>
When I use the textbox, the ID will post, but not when I use that actionlink. How can I get the actionlink to post the Id?
Again, I am new to this so forgive me if I am not explaining it all too well.
Upvotes: 1
Views: 80
Reputation: 1599
Try this
@Html.ActionLink("Title","Action", "Controller", new { id = item.MetadataDocumentSetId }, null)
Upvotes: 0
Reputation:
ActionLink
doesn't post values, if you mean by post that you want to load a page based on the id you shoud do this (this is a GET, not a POST):
Controller method:
public ActionResult GetById(string id)
{
var currentId = id;
// do something with currentId
return this.View()
}
ActionLink:
@Html.ActionLink("link text", "GetById", "MyController", new { id = "12-34"}, null)
Upvotes: 1
Reputation: 678
Try
<span>@Html.ActionLink("Link text", "ShowDocumentMetadata", "Metadata", new { id = item.MetadataDocumentSetId.ToString()}, null)</span>
You're selecting the wrong ActionLink method. For more info - https://msdn.microsoft.com/en-US/library/system.web.mvc.html.linkextensions_methods(v=vs.118).aspx
But you want to pass the parameter through in RouteValues
Upvotes: 0
Reputation: 118937
You are using the wrong overload of Html.ActionLink
, try this instead:
@Html.ActionLink(item.MetadataDocumentSetId.ToString(), "ShowDocumentMetaData",
"Metadata", new { id = item.MetadataDocumentSetId }, null)
Upvotes: 0