c# - How to show partial view -


i have page information, want add there list (in form of table) within partial view. user has have ability sort switching radio box.

my problem: code works fine (i have tried in separate view), when try switch radio button (they submit page on change , activate 2nd method, create new model according radio button) html code partial view.

in other words:
want : html view1 + html mypartial
get: html mypartial
suppose problem here (calling mypartial):

@html.action("_showemployeeprojects", "employee") 

but when try use this:

@html.partial("partial/_showemployeeprojects") 

i this:

the model item passed dictionary of type
'btghrm.models.employeejobdataviewmodel', dictionary requires model item of type 'system.collections.generic.list`1[btghrm.models.employeeprojecthistorymodel]'.

my controllers code:

    public partialviewresult _showemployeeprojects()      {         int empid = hrmsession.selectedemployeeid;          using (var db = new hrmentities())         {             list<employeeprojecthistorymodel> list = (from t1 in db.projectworkers                                                       join t2 in db.projects                                                       on t1.projectid equals t2.projectid                                                       (t1.workerid == empid && t1.isactive == true)                                                       select new employeeprojecthistorymodel()                                                       {                                                           projectname = t2.projectname,                                                           activity = t1.activity,                                                           startdate = t1.startdate,                                                           enddate = t1.enddate                                                       }).tolist();             return partialview("partial/_showemployeeprojects",list);         }     }     [httppost]     public partialviewresult _showemployeeprojects(string activeonlyselect)     {         int empid = hrmsession.selectedemployeeid;         list<employeeprojecthistorymodel> list;         using (var db = new hrmentities())         {             if (activeonlyselect.equals("both"))             {                 list = (from t1 in db.projectworkers                         join t2 in db.projects                         on t1.projectid equals t2.projectid                         (t1.workerid == empid)                         select new employeeprojecthistorymodel()                         {                             projectname = t2.projectname,                             activity = t1.activity,                             startdate = t1.startdate,                             enddate = t1.enddate                         }).tolist();                 list.orderby(x => x.startdate);             }             else             {                 list = (from t1 in db.projectworkers                         join t2 in db.projects                         on t1.projectid equals t2.projectid                         (t1.workerid == empid && t1.isactive == true)                         select new employeeprojecthistorymodel()                         {                             projectname = t2.projectname,                             activity = t1.activity,                             startdate = t1.startdate,                             enddate = t1.enddate                         }).tolist();                 list.orderby(x => x.startdate);             }         }         return partialview("partial/_showemployeeprojects", list);     } 

my partial:

@model    list<btghrm.models.employeeprojecthistorymodel> @using (html.beginform("_showemployeeprojects", "employee", formmethod.post, new { type = "main" })) { <table>     <tr>         <td>             @html.radiobutton("activeonlyselect", "activeonly", true, new { id = "activeonlyselect0", onchange = "this.form.submit();" })             <label for="activeonlyselect0">@resources.localization.show_only_actual</label>         </td>     </tr>     <tr>         <td>             @html.radiobutton("activeonlyselect", "both", new { id = "activeonlyselect1", onchange = "this.form.submit();" })             <label for="activeonlyselect1">@resources.localization.show_all_data</label>         </td>     </tr> </table> } @{     webgrid grid = new webgrid(model, cansort: false, rowsperpage: 15); if (model.any()) {      @grid.gethtml(     tablestyle: "table",     headerstyle: "table_headerstyle",     footerstyle: "table_pagerstyle",     rowstyle: "table_rowstyle",     alternatingrowstyle: "table_alternatingrowstyle",     selectedrowstyle: "table_selectedrowstyle",     columns: grid.columns(         grid.column("projectname", resources.localization.project, style: "p30"),         grid.column("activity", resources.localization.activity, style: "p30"),         grid.column("startdate", resources.localization.start_date, format: @<text>             @if (item.startdate != null)             {                 <span class="display-mode"><label id="startdatelabel">@item.startdate.toshortdatestring()</label></span>                 @html.hidden("model.startdate", (object)item.startdate.toshortdatestring())             }             else             {                 <span> &nbsp; </span>             }</text>, style: "p10"),         grid.column("enddate", resources.localization.end_date, format: @<text>             @if (item.enddate != null)             {                 <span class="display-mode"><label id="enddatelabel">@item.enddate.toshortdatestring()</label></span>                 @html.hidden("model.enddate", (object)item.enddate.toshortdatestring())             }             else             {                 <span> &nbsp; </span>             }</text>, style: "p10")     )     ) } 

}

it looks passing wrong model partial. structure be:

in principal layout:

@model system.collections.generic.list[btghrm.models.your_model] <!-- html´s stuff. can access your_model.employee´s list --> @html.partial("partial/_showemployeeprojects", model.projects) 

in partial, remember model passing main layout:

@model system.collections.generic.list[btghrm.models.your_model.projects] <!-- html´s stuff --> 

then, in controller, must return return:

[httppost]     public partialviewresult _showemployeeprojects(string activeonlyselect)     {         // magic            // model should list[btghrm.models.your_model]         partialview("partial/_showemployeeprojects", model);     } 

model:

public class your_model {    list<employee> employees;    list<project> projects; ..... } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -