Html.ActionLink (): new { route value} is acting strangely. I don't know where length = 17 parameter is coming from
I've this link on a page
<% = Html.ActionLink(item.Title, "Edit", "ArticleManagement",
new { id = item开发者_如何学运维.ArticleDataID })%>
and a simple method to receive the article Id
public ActionResult Edit(int id)
{
//Do something
}
Unfortunately, I'm getting an error" parameter dictionary contains a null value for parameter id of int32 for Edit(Int32)..."
When I check the Url, I see something like "http://localhost:59786/ArticleManagement/Edit?Length=17"
What is "Length=17"? and what's doing there? Anyway, so far I'm working with a collection that has only 3 items on it.
Thanks for helping
You need to add null as the last parameter:
<%=Html.ActionLink("Title", "Edit", "ArticleManagement",
new { id = 1 }, new { @class = "link-class", attr = "attribute value" })%>
I think it uses you route values as html attributes without the null.
I've had this happen as well, it seems to happen when the actionlink can't match to a route.
Length 17 corresponds to the length of articlemanagement.
Edit: It might have something to do with the overload of ActionLink.
精彩评论