S
S
Sergey Konovalov2015-12-04 13:32:42
ASP.NET
Sergey Konovalov, 2015-12-04 13:32:42

How to set up serialization of request parameters?

Good afternoon, the problem is this:
there is a model for adding something:

public class Person
{
     public int Id { get; set; }
     public int Name { get; set; }
     public IEnumerable<Tag> Tags{ get; set; }
}

public class Tag
{
     public int Id { get; set; }
     public int Name { get; set; }
}

and there is a submit form of this model
@using (Ajax.BeginForm("AddFoo", "MyController", new AjaxOptions { UpdateTargetId = myId, HttpMethod = "POST", InsertionMode = InsertionMode.ReplaceWith }))
{
...
}

The problem is that the Tags field is not passed, apparently ToString() is simply called for it and in the request it looks like Tags=System.Collections.Generic.List....
How to fix this? Maybe I'm doing something wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dasha Tsiklauri, 2015-12-04
@zakar1ya

in the HTML code inside the form it should be some kind of input with the names
"Tags[0].Id"
"Tags[0].Name"
"Tags[1].Id"
"Tags[1].Name"

E
eRKa, 2015-12-05
@kttotto

I think that you do not have a field for Tags on the form. If you do not need to enter data manually for Tags on the form, then make it hidden, but initialize it with the data that you want to receive when receiving data from the form.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question