Home > DeveloperSection > Forums > Two model type in one View
Andrew Watson
Andrew Watson

Total Post:39

Posted on    November-03-2014 10:53 PM

 ASP.Net C#  ASP.NET MVC  Mvc4 

 1 Reply(s)
 904  View(s)
Rate this:

I have a concern. I am populating a list from controller and showing a table. Now upon clicking of a button in table row, i want to populate modal popup for webform, which is a partial view. My problem is, when i am using List Type model, i am not able to convert that model from list to simple as i have to pass simple model to render webform. My code is as below:


@model List<MvcApplication3.Models.ModelList>

@foreach (var item in Model)





public class ModelList


     public string Name { set; get; }

     public string Product { set; get; }

     public string Status { set; get; }

     public string Password { set; get; }

     public string Email { set; get; }



@model MvcApplication3.Models.ModelList

@using (Html.BeginForm())





List<ModelList> objList = new List<ModelList>();

return View(objList);

How can i be able to use same model in both ways.

Sanjay Sharma
Sanjay Sharma

Total Post:45

Posted on    November-04-2014 1:22 AM

@foreach (var item in Model)
    // foreach is used to show data in table
    @Html.Partial("PartialView", item)

You need to tell it to use your item in the partial

Don't want to miss updates? Please click the below button!

Follow MindStick