How to get formcollection using ajax.actionlink

你说的曾经没有我的故事 提交于 2019-12-11 16:13:42

问题


I have a controller with the codes like this:

[AcceptVerbs("POST")]
public ActionResult Create(FormCollection collection)
{
    //why is that the collection is null?
}

I am calling this action using the ajax.actionlink.

my problem is the collection is null, unlike if i use the submit(input) button the formcollection has values.


回答1:


FormCollection has a default binder associated with it which always initializes the collection and you should never get null. It is more likely that you have an empty collection when using Ajax.ActionLink in contrast to when using a form submit button. This is because the ActionLink method doesn't POST any form values when it performs the AJAX request.




回答2:


You need to use Ajax.BeginForm



来源:https://stackoverflow.com/questions/1550219/how-to-get-formcollection-using-ajax-actionlink

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