开发者

Any quick ways to serialize input data to List<object> with jQuery?

Let's say I have an object:

Person
{
   public string FirstName {get;set;}
   public string LastName {get;set;}
}

On the client side, the user gets a table with a whole bunch of input texts for adding/editing these "people".

<tr>
  <td><input type="text" name="FirstName"/></td>
  <td><input type="text" name="LastName"/></td>
</tr>
<tr>
  <td><input type="text" name="FirstName"/>开发者_Python百科;</td>
  <td><input type="text" name="LastName"/></td>
</tr>
<tr>
  <td><input type="text" name="FirstName"/></td>
  <td><input type="text" name="LastName"/></td>
</tr>

The controller action is expecting a List<Person>:

public ActionResult SavePeople (List<Person> people)
{ ..... }

Input data is submitted to the Action with AJAX call. What is the easiest way to serialize all that input data? I don't want to manually build a JavaScript array, etc. Something like $('table input').serialize()...

Thank you!


If it's already wrapped in a form...

$('form').serialize();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜