Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Look into ViewModel objects, objects you create whose purpose in life is to carry data to and from your Views. The Models folder created for you by default in a new MVC project would hold exactly those classes.</p> <p>You have options besides the ViewModel object methodology, but none are as clean. (The <code>ViewData</code> dictionary is around to help but it's not intended to be the primary means of providing data to your views.) Here's an example of how to set the Model property of the ViewData object to an instantiated, populated viewmodel instance:</p> <pre><code> public ActionResult SiteContent(string strSlug) { SiteContentVM model = new SiteContentVM(); SiteService siteService = new SiteService(); model.Slug = siteService.GetALittleSlimyCreature(strSlug); model.List1 = siteService.GetList1(); model.List2 = siteService.GetList2(); ViewData.Model = model; return View(); } </code></pre> <p>You can now create a strongly typed view (complete with intellisense) to reference any properties of your ViewModel object instance from within your view simply through the <code>Model</code> property:</p> <pre><code>&lt;% foreach (var item in Model.List1) { %&gt; &lt;% Html.Encode(item.StringField) %&gt; &lt;!-- &lt;= writing a property --&gt; &lt;% Html.RenderPartial("PartialNameHere", item); %&gt; &lt;!-- &lt;= the equivalent of a usercontrol --&gt; &lt;% } %&gt; </code></pre> <p>As you see above the process of getting data from the database does not change for MVC. You do it just as you would in a normal webforms project. (...usually this involves instantiating a business logic or service class of some sort rather than actually writing the code in the MVC project.)</p> <p>Enjoy MVC!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload