View Model looks like this:
public class AsmenysInfoViewModel2
{
public asmenys_info Asmenys_info { get; set; }
public List<miestai> Miestai { get; set; }
public string Test { get; set; }
}
And there are two actions. Get and Post.
public ActionResult Index(long? id)
{
var model = new AsmenysInfoViewModel2();
model.Test = "Test";
model.Asmenys_info = BllFactory.DalFactory.AsmenysInfoDal.GetById(id.Value);
return View(model);
}
[HttpPost]
public ActionResult Index(AsmenysInfoViewModel2 asmenys_info)
{
var model = asmenys_info;
return View(model);
}
And my view looks like this:
@model MODELS.AsmenysInfoViewModel2
@{
ViewBag.Title = "Index";
}
@using (Html.BeginForm("Index", "AsmenysInfo", FormMethod.Post))
{
@Html.ValidationSummary()
@Html.TextBoxFor(m => m.Asmenys_info.adresas)
<input type="submit" value="Išsaugoti" />
}
Doesn't matter if I use EditorFor or TextBoxFor - result is same. My model property "Asmenys_info" on posting is always null. If my class AsmenysInfoViewModel2 would not contain asmenys_info type property and would contain only "string, int etc" (no strongly typed) - it would work. My question is :
How to post View Model which has strongly typed property which on posting would not be null?
public ActionResult Index(asmenys_info asmenys_info)topublic ActionResult Index(AsmenysInfoViewModel2 asmenys_info)- Shashank Soodjsonobject in jquery and then posting the form. - Shashank Sood