Cannot get @Ajax.ActionLink to work in a partial view, get “Cannot resolve” error

回眸只為那壹抹淺笑 提交于 2019-12-13 19:44:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!