I have been getting into MVC ASP.NET, the potential is very exciting. I have become slightly stuck on a bit and wondered if anyone could give advice, please.
I have worked out how to bundle type object into the viewdata and then access them in a view.
In the view I pick up my viewdata object and assign it to corresponding type.
@using MyPro.Models;
@{
var viewDataMyObj = ViewData["MyObj"] as MyObj;
}
I then pick it up further down and successfully access my {get,set} and populate a DropDownListFor...
@Html.DropDownListFor(x => viewDataMyObj.myVar, new SelectList((IEnumerable<SelectListItem>)viewDataMyObj.mySel.OrderBy(c => c.Value), "Value", "Text", "Select All"), new { @Class = "form-control" })
So, mySel is in my Model and works. It's the string myVar, I can't assign it as an id field. It literally takes "viewDataMyObj.myVar" and puts it as an ID, not the contents of myVar which is "hello". I'm definitely lacking a bit of knowledge at this and would be grateful for any advice.