I have model, which use by EntityFramework
public class Goal
{
public int ID { get; set; }
public string GoalName { get; set; }
public int GoalTarget { get; set; }
}
My Jscript code
var GoalName = $('input[name="GoalName[]"]').serialize();
var GoalId= $('input[name="GoalId[]"]').serialize();
alert(GoalName);
$.post('/Home/UpdateGoals', { GoalName: GoalName, GoalId: GoalId}, function (data) {
});
Question is - how to correctly receive data from client to controller? Use form['paramname'] and next save db or use special created ViewModel for receiving data and next save db ?
For example I should create new modelView
class GoalView
{
public string[] GoalName { get; set; }
public string[] GoalId { get; set; }
}
and now i controller I can foreach data from this model and save db ?
public ActionResult UpdateGoals(GoalView goalview)
{
how I can save data from goalview to db.Goals (which using Goal model) ??
return Content();
}
Could you please advise how to do correctly and provide some examples ?