问题
I am using MVC3, ASP.NET 4.5, C#, Razor.
I have successfully got the Ajax.ActionLink working from my main page which contains a table and records with each containing a link. The Ajax.ActionLink "replaces" the record in all cells within the element. I use a partial view to do this replacing in:
<td>col1</td><td>col2</td>
However col1 should retain the Ajax.Actionlink as it will be required again, so my partial view should be:
<td>@Ajax.ActionLink("Delete",...)</td><td>col2</td>
But I get a
"cannot resolve symbol ActionLink"
error.
Am I missing a reference in the partial view. I did try System.Web.MVC.Ajax, but this failed.
Thanks for any help.
EDIT1:
Seems no issue with:
@Html.ActionLink(...)
EDIT2:
Full ActionLink code:
@Ajax.ActionLink("Delete",
"AjaxDelete",
"Order",
new {id = ViewBag.id},
new AjaxOptions {
UpdateTargetId = ViewBag.rowname,
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET"
});
回答1:
The error message is misleading. The compiler cannot create an anonymous type from a dynamic property as it has no idea what type it is.
Add an (int)
cast to ViewBag.id
to make the anonymous field strongly typed.
Also do the same same for Viewbag.rowname
(string I assume?)
e.g.
@Ajax.ActionLink("Delete",
"AjaxDelete",
"Order",
new {id = (int)ViewBag.id},
new AjaxOptions {
UpdateTargetId = (string)ViewBag.rowname,
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET"
});
来源:https://stackoverflow.com/questions/24824782/cannot-get-ajax-actionlink-to-work-in-a-partial-view-get-cannot-resolve-erro