Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
<a href="http://www.codeproject.com/Articles/698246/ASP-NET-MVC-Special-Views-Partial-View-and-Layout">ASP.NET MVC Special Views - Partial View and Layout</a>[<a href="http://www.codeproject.com/Articles/698246/ASP-NET-MVC-Special-Views-Partial-View-and-Layout" target="_blank" title="N<a href=">^</a>

This is my partialview.cs
C#
@using DirectTracIncident.Models;
@model IEnumerable<directtracincident.models.incidentmodel>

@{
    ViewBag.Title = "Index";
}


@Styles.Render("content/incident.css")
@using (Html.BeginForm())
{
    <div>
        <div class="main">

            <div class="div1">
                <a href=" "><img src="images/logo.png" /></a>
            </div>
            <div>
                <ul class="ul">
                    <li><a>Product</a></li>
                    <li><a>Solution</a></li>
                    <li><a>Support</a></li>
                    <li><a>Purchase</a></li>
                    <li><a>Download</a></li>
                    <li><a>Company</a></li>
                </ul>
            </div>
            <div class="div2">
                <div class="div4">

                    <div class="div3">Logout</div>
                    <div class="div3"><img src="images/shopcart" /></div>
                    <div class="div3"><img src="images/phone.png" /></div>
                    <div class="div3"><img src="images/search_filter.png" /></div>

                </div>
                <div class="div4">
                    <div class="div3">Download</div>
                    <div class="div3">Live Demo</div>
                </div>

            </div>

        </div>
        <div class="div5">
            <table>
                <tr>
                    <td>Home</td>
                    <td><img src="../../images/seperator.png"></td>
                    <td>Support</td>
                    <td><img src="../../images/seperator.png"></td>
                    <td>Direct-Trac</td>
                    <td><img src="../../images/seperator.png"></td>
                    <td>View Incidents</td>
                </tr>
            </table>
        </div>
        <div class="div6">
            <div class="main1">
                <div class="page_title">Incidents</div>
                <a class="newincident" href="">New Incident</a>
            </div>
            <div class="div8">
                <div class="div7">
                    @Html.Label("User Id")
                </div>
                <div class="div9">
                    @Html.TextBoxFor(m=>m.uid)
                </div>
                <div><input type="submit" value="submit" /></div>
            </div>
            <div class="div10">
                <div class="div12">
                    <div class="div11">
                        <div class="div12">Incidents</div>
                        <div class="div16">Status</div>
                    </div>
                    @foreach (var i in Model)
                    {
                        <div>
                            <div class="div14">
                                <span class="div15">@i.title</span><br />
                                platform:"@i.platFormName"
                                <div class="div13">
                                    @i.statusName
                                </div>
                            </div>

                        </div>
                    }
                </div>

            </div>
        </div>

    </div>
}

and this is my Index.cs
C#
@model IEnumerable<directtracincident.models.incidentmodel>
@{
    ViewBag.Title = "Index";
}
@foreach(var i in Model)
{
<div>
    @Html.Partial("PartialView",i)
</div>
}
Posted
v2

At first look in your code there are some things that are not OK from my point of view:

1.In your partial view you should specify the model like @model IEnumerable<SomeClass>
by specifying clear what are the object types used in your enumeration;

2.In your view view, where the partial view are rendered, you also should specify the class used like in 1st point above: @model IEnumerable<SomeOtherClass>;

3.The page common part CSS files used in the page, and the code block with ViewBag.Title = "Index"; have to be specified in the view page and not in the partial view;

4.You should check in your controller, where your Model for the view page is created and the view is activated. Also it will be nice to share with us this code, maybe also there are some problems!
 
Share this answer
 
v3
Comments
NithyaGopu 28-Mar-14 3:14am    
public partial class IncidentModel
{
public string title { get; set; }
public string platFormName { get; set; }
public string statusName { get; set; }
//public string user_Id { get; set; }
public string uid { get; set; }
//public string u_Id { get; set; }
public List<incidentmodel> Incidents(string u_Id)
{
DTSyncdbTestRPEntities d = new DTSyncdbTestRPEntities();
var query = (from p in d.problems
join t in d.tblUsers on p.sid equals t.sid
join c in d.SU_Control on p.ControlId equals c.ControlId
join pl in d.SU_Platform on c.PlatformId equals pl.PlatformId
join s in d.status on p.status equals s.status_id
where p.uemail == u_Id
select new { p.title, s.sname, pl.PlatformName });
List<incidentmodel> list = new List<incidentmodel>();
foreach (var x in query)
{
IncidentModel i = new IncidentModel();
i.title = x.title;
i.statusName = x.sname;
i.platFormName = x.PlatformName;
list.Add(i);
}
return (list);
}
}
} this is my model class and below is my controller action
public ActionResult Index(IncidentModel inc)
{
string u_Id =inc.uid;
return View(new IncidentModel().Incidents(u_Id));

}
NithyaGopu 28-Mar-14 3:15am    
i have created only one class in model as from your second point some other class means?
Raul Iloc 28-Mar-14 3:34am    
Now your view code is more clear, but the next aspecta remains totally unclear and wrong: you are using the same Model in both places: View and PartialView, and in your View; and in your View for each item from your Model (that is a list of IncidentModel objects) you are passing to the PartialView an object of type Incident, but your the PartialView is expected to get an object of type list of IncidentModel!?

It seems that you don't need any partial view and your code could be used directly in view.So can you describe textually what are your trying to do in this View and also in the Partial View?
In my Controller i JUST retrned return View("PartialView",new IncidentModel().Incidents(u_Id));
and changed my Index.cs as
@Html.Partial("PartialView","Model")
I got output
and thank you..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900