I know, there's a lot of questions, tried the solutions, neither of them worked. Basically, I'm stuck...
ViewModel:
public class CreateStrengthViewModel
{
public string Strength { get; set; }
public IEnumerable<Categories.CategoryViewModel> Categories { get; set; }
public int Category { get; set; }
}
Post:
-----------------------------7e01e1381a08c2
Content-Disposition: form-data; name="__RequestVerificationToken"
iErDomlK5vCWAFFMlGkb2-HgLCoquxfeIlYeI3pmrsW_5VSD8-huS6JbCdA4OAg4s8nMgqKAHPHArVoQ3GzfFWf2I-Yx6iWgvkWRNI6jiKA1
-----------------------------7e01e1381a08c2
Content-Disposition: form-data; name="Strength"
FMC Extra
-----------------------------7e01e1381a08c2
Content-Disposition: form-data; name="Category"
1
-----------------------------7e01e1381a08c2--
Controller:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(
[Bind(Include = "Strength,Category")]
CreateStrengthViewModel strength)
{
using (StrengthServices service = new StrengthServices(new ImperialTobacco_Database()))
{
//service.CreateAndSave(strength);
...
}
}
}
The strength inside the controller method is null whatever I'm doing. The browser sends the data as you can see, but the ModelBinder just won't do a thing. Oh, and by the way: The very same code works for a different ViewModel with different Include fields. Yeah, I've tried to remove the Bind, or bind just one of the incoming variables nothing changes.
Funny thing is; this is working:
public class CreateCompanyViewModel
{
public string Name { get; set; }
public string Color { get; set; }
public IEnumerable<MarketViewModel> MarketsOfOperations { get; set; }
public IEnumerable<int> SelectedOperations { get; set; }
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Name,Color,SelectedOperations")] CreateCompanyViewModel company)
{
using (CompanyServices service = new CompanyServices(new ImperialTobacco_Database()))
{
service.CreateAndSave(company);
return RedirectToAction("Index", "Management");
}
}
I'll be honest, I have no idea what's going on and why the ModelBinder picks up nothing from the posted data, especially as a nearly identical one works perfectly.
P.S.: I tried changing the Property and Bind names yet again no luck.