I have been developing an application that uses Models that are based on a single USP/dbml and using ViewBags to populate the look up lists for data entry and edit views. This has been ok until I start to implement business logic. The Dropdownlists because they are done with ViewBag.llkup aren't available in the Script functions unless explictly passed to the function. I could create a single model that had multiple USP in it. I was wondering what is considered best practice concerning this issue. Thanks Bruce I have the following code in a controller:
using (var dc = new usp_TM_Select_ShortNameDataContext())
{
String[] s = this.User.Identity.Name.Split('\\');
string[] s2 = s[1].Split('.');
string a = s2[0] + '.' + s2[1];
ViewBag.Message = a.ToString();
ViewBag.DetailsList = new SelectList((System.Collections.IEnumerable)dc.usp_TM_Select_ShortName().ToList(), "short_title", "short_title");
var poc = new usp_ARD_Select_POCDataContext();
return View(poc.usp_ARD_Select_POC().Single());
}
Both are strongly typed views but how do I return both if they are in a single model to the view so that they can be used (accessed)? I have more complex examples where I have a Single record returned with multiple lookups. I am currently doing this with ViewBag and would like to use ViewModels. Thanks Bruce
Having the view strongly typed to a ViewModel would be my choice.
You can see examples here:
http://www.bidn.com/blogs/mbrown/development/2139/mvc-3-view-models
When do I use View Models, Partials, Templates and handle child bindings with MVC 3