开发者

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

开发者 https://www.devze.com 2023-02-24 11:06 出处:网络
Let\'s say I have an object: Person { public string FirstName {get;set;} public string LastName {get;set;}

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

精彩评论

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