PDA

View Full Version : [CLOSED] Submit form in the model has a list of objects.



threewonders
Oct 23, 2014, 5:12 PM
Hello good.

I have a problem when doing a submit form in the model has a list of objects.

model



[Model(Name = "ReviewAll")]
public class ReviewAll
{
[ModelField(IDProperty = true, UseNull = true)]
[Field(Ignore = true)]
public int? ReviewID
{
get;
set;
}

[PresenceValidation]
public string Registration
{
get;
set;
}

public List<Wheel> Whell
{
get;
set;
}
}

[Model(Name = "Wheel")]
public class Wheel
{
[ModelField(IDProperty = true, UseNull = true)]
[Field(Ignore = true)]
public int? WheelID
{
get;
set;
}

[PresenceValidation]
public int ReviewID
{
get;
set;
}

public int Axis
{
get;
set;
}

public int Index
{
get;
set;
}

}



controller



public ActionResult RenderView()
{
try
{
ReviewAll ra = new ReviewAll();

List<Wheel> w = new List<Wheel>();

for (int i = 0; i <= 3; i++)
{
Wheel one = new Wheel();
one.Axis = i;
one.Index = i;
w.Add(one);
}

ra.Registration = "test";
ra.Whell = w;

return View(ra);
}
catch
{

}
}

public ActionResult SuccessSubmit(ReviewAll person)
{
X.Msg.Alert("Submit", JSON.Serialize(person)).Show();
return this.FormPanel(true);
}



view




@model Euromaster.Models.ReviewAll

/*
...
*/


X.NumberFieldFor<int>(m => m.Whell[0].Axis).FieldLabel("Axis")
X.NumberFieldFor<int>(m => m.Whell[1].Axis).FieldLabel("Axis")
X.NumberFieldFor<int>(m => m.Whell[2].Axis).FieldLabel("Axis")



When I do submit, Whell this to null

What am I doing wrong ??

As I can fix ??

Thank you very much and greetings !!

Daniil
Oct 24, 2014, 5:57 AM
Hi @threewonders,

This throws an Exception for me.

X.NumberFieldFor<int>(m => m.Whell[0].Axis).FieldLabel("Axis")



I had to remove <int>.

The RenderView controller action also throws a compile error.

Also you don't post a full view and I don't see how you submit the values from client side.

Ideally, we would love to have something that we can copy, paste and run without any changes (or very minor ones like renaming the namespace of the Model class). Almost all other cases leaves a lot of space for guesswork.

So, I guess the values are just not submitted to server in your case.

I just tried your code with this View and it works well.

@model Work2MVC.Controllers.ReviewAll
@{
var X = Html.X();
}

<!DOCTYPE html>
<html>
<head>
<title>Ext.Net.MVC v2 Example</title>
</head>
<body>
<form>
@X.ResourceManager()

@X.NumberFieldFor(m => m.Whell[0].Axis).FieldLabel("Axis")
@X.NumberFieldFor(m => m.Whell[1].Axis).FieldLabel("Axis")
@X.NumberFieldFor(m => m.Whell[2].Axis).FieldLabel("Axis")

@X.Button().Text("Submit").DirectClickAction("SuccessSubmit")
</form>
</body>
</html>