Posting int arrays to MVC controller - what would be the correct method signature?

馋奶兔 提交于 2019-12-10 17:04:54

问题


Below is a screenshot of the POST request (using Firebug Net panel) I am sending to my ASP.NET MVC2 controller.

This is the controller / action method that receives the POST request:

public ActionResult Search(int[] skill, int[] discipline, int[] education, int[] marketsector){ ... }

The parameters POSTed seem to me to be in the correct form, however the action method receives four null arguments. Could you please tell me what should the method signature look like on the server side? Or a better way of posting these four integer arrays to my MVC2 controller?


回答1:


They could look like this:

<input type="text" name="discipline" value="6" />
<input type="text" name="marketsector" value="5" />
<input type="text" name="marketsector" value="7" />
<input type="text" name="marketsector" value="3" />
<input type="text" name="skill" value="3" />
<input type="text" name="skill" value="8" />

And here's a blog post you may take a look at. And a similar one.



来源:https://stackoverflow.com/questions/5002952/posting-int-arrays-to-mvc-controller-what-would-be-the-correct-method-signatur

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