Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass a list of data between views in MVC 3.0?
    primarykey
    data
    text
    <p>I am building my first MVC app after following the Music Store tutorial and have ran into some problems when trying to pass data between strongly typed views. </p> <p>I have two datatypes with their own strongly typed views</p> <p>Customer Customer Site</p> <p>In the index view of customer site (which returns a lits of customer sites) i need to display the customer name next to each site address, the view is strongly typed to customer site but the customer name is stored in the customer table so it wont allow me to access this directlty from the model?</p> <p>I know that one option is to use the viewbag, i have successfully done this to display the Customer Name in a drop down list on my create view using the following code </p> <p>Customer Site Controller/////////</p> <pre><code>public ActionResult Create() { ViewBag.Id = new SelectList(db.Customers, "Id", "CustomerName"); return View(); } </code></pre> <p>Index view//////////</p> <pre><code>@Html.DropDownListFor(model =&gt; model.CustomerId, (IEnumerable&lt;SelectListItem&gt;)ViewBag.Id) </code></pre> <p>This works fine but now i need to the customer name to be inserted each table row rather than a drop down list. Can anyone kindly offer any pointers on how i can retrieve a list of customer names to be rendered in a table in the index view of the customer site? </p> <p>Also is the viewbag the best way to pass data between views or are there other alternative methods? Is there a way to strongly type a view with multiple data types?</p> <p>Any advice anyone can offer would be great.</p> <p>Kind Regards</p> <p>Liam</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.
 

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