ViewModel
namespace VendorFinancing.Web.Models
{
public class CreateApplicationViewModel
{
public Application Application { get; set; }
public List<Equipment> Equipments { get; set; }
public string SelectedVendorId;
public IEnumerable<SelectListItem> VendorList { get; set; }
}
}
Controller
public ActionResult Create()
{
var model = new CreateApplicationViewModel();
model.VendorList = new List<SelectListItem>() { new SelectListItem() { Text = "London", Value = "1" },
new SelectListItem() { Text = "New York", Value="2" } };
return View(model);
}
[HttpPost]
public ActionResult Create(CreateApplicationViewModel model)
{
return View(model);
}
View
@using (Html.BeginForm("Create", "Application", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
<div class="form-horizontal">
<h2>Submit Application </h2>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<h3>Pick Vendor</h3>
<div class="form-group">
<div class="col-md-2">
@Html.LabelFor(c => c.SelectedVendorId)
</div>
<div class="col-md-10">
@Html.DropDownListFor(model => model.SelectedVendorId, Model.VendorList)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10 pull-left">
<input type="submit" value="Create" class="btn btn-default pull-left" />
</div>
</div>
</div>
}
This is very basic create. When form is submitted SelectedVendorId
is still null. I tried the same example in different it is still working. I am not able to figure out the reason. Any help is appriciated.
EDIT: found my mistake SelectedVendorId
didnt have get and set. After making it a property it worked.