i have two model classes Money and MoneyType.
a money object containe a List of TypeMoney property
In my money strongly typed view, that's the main index view there's html table for the list of type Money objects
i want to append TypeMoney object as editor template row to table dynamicly by jquery, so that when the user want to fill one row , he click on AddMoney button, then only one row is displayed in this table. (the user will fill typemoney informations). and he click again on AddMoney button, when he want to fill information in an other row and so on.
for this i have implemented an editor template and i created a partial view _create.cshtml for this editor template so that i can append this partial as row
untill he submit all to controller: the money object data with its collection of typeMoney objects data.
In the controller index action i passed a model "money" to Index view
My issue is when i submit this form, the list of type money objects is sent null to the controller
How i can add a type money object to Editor template collection and send this collection without to be null to controller
sorry for the lot of a details, because i want that all to be clear and understandable . if there's a thing not cleer. please tell me.
model classes
public class Money{
public int StructureId {get; set;}
// public enum Quarter:byte{ FirstQuarter = 1, SecondQuarter=2,
// ThirdQuarter=3, FourthQuarter=4}
public Querter Quarter{get; set;}
public int Year {get; set;}
public List<TypeMoney> MoneyTypes {get; set;}
}
public class TypeMoney{
//public enum Type:byte{ Bill= 1, Coin=2}
public Type Type{get; set;}
//public enum Value = {one = 1, tow=2, five=5, ten=10, Etc};
public Value Value{get; set;}
public int Number{get; set;}
}
controller code
public ActionResult Index()
{
ViewBag.StructureId= new SelectList(GetStructures(), "Id", "Name");
ViewBag.Year = new SelectList(GetYears());
ViewBag.Quater = new SelectList(Enum.GetValue(typeof(Quarter));
return View()
}
//partial view for Editor template
public PartialViewResult _Create(Money money)
{
return PartialView();
}
//save money with list of typeMoney objects
[HttpPost]
public ActionResult Index(Money money)
{
//code for save in database
}
Here is my editor template
@model ProjectName.TypeMoney
<tr class="insertMoneyTr">
<td>
@Html.DropDownListFor(model => model.Type, null, "--selectionnez--",
new { @class = "typeMoney form-control" })
</td>
<td>
@Html.DropDownListFor(model => model.Valeur, null, new { @class =
"valueMoney form-control" })
</td>
<td>
@Html.TextBoxFor(model => model.Numbre, new { @class = "nombre form-
control" })
</td>
<td>
<button class="deleteMoney btn btn-danger glyphicon glyphicon-
remove">
</button>
</td>
</tr>
Partial View _create.cshtml
@model ProjectName.TypeMoney
@Html.EditorForModel();
The jquery code for display a partial view as row appened to table
//the id of button that append editor template is AddMoney
$("#AddMoney").click(function (e) {
e.preventDefault();
$.ajax({
url: "Money/_Create",
type: 'Get',
dataType: 'html',
success: function (result) {
$("#listEspecesDiv tbody").append(result);
}
});
});