c# - How to inherits differents models in the same view in ASP MVC -


i developing asp .net mvc 3 application using c# , sql server 2005.

i using entity framework , code first method.

i have partial view 'gestion.ascx' contains form (textbox , listbox).

this view use viewmodel 'flowviewmodel'.

i want view use model 'gamme' have.

i try put them both in 'inherits markup' but statements became underlined in red.

infact, explain more question :

i used flowviewmodel in partial view in order load data in list boxfrom differents models.

now want store values selected , entred in local variables.

i can't pass model 'gamme' controller because view 'gestion' not using model 'gamme'.

this code of partial view 'gestion' :

<%@  language="c#" inherits="system.web.mvc.viewusercontrol<mvcapplication2.models.flowviewmodel>" %>  <% using (html.beginform("save", "anouar")) { %>     <%: html.validationsummary(true) %>     <fieldset class="parametrage">         <legend>gestion de gamme</legend>          <div><%:html.label("poste :")%><%: html.dropdownlist("selectedposte", model.postesitems)%><input type="checkbox" name="option1" value="poste initial" id= "chkmain" onclick="test();"/>poste initial<input type="checkbox" name="option2" value="poste final" id= "chkfirst" onclick="test2();"/>poste final</div>            <div><%:html.label("nombre de passage :")%><%: html.editorfor(x=>x.yourgammemodel.nbr_passage)%></div>         <div><%:html.label("position :")%><%: html.editorfor(x=>x.yourgammemodel.position)%></div>         <div><%:html.label("poste précédent :")%><%: html.dropdownlist("posteprecedentselected", model.postesitems)%></div>         <div><%:html.label("poste suivant :")%><%: html.dropdownlist("postesuivantselected", model.postesitems)%></div>           <div><input type="submit" value="enregistrer" id="btnsave"  /></div>          </fieldset> <% } %> 

and code of model 'flowviewmodel' :

namespace mvcapplication2.models {     public class flowviewmodel     {          [key]         public string idv { get; set; }         [notmapped]         public selectlist postesitems { get; set; }          public list<profile_ga> profile_gaitems { get; set; }         public list<gamme> gaitems { get; set; }          public gamme yourgammemodel { get; set; }          public int selectedprofile_ga { get; set; }          public int selectedgamme{ get; set; }          public int selectedposte { get; set; }          public int posteprecedentselected { get; set; }          public int postesuivantselected { get; set; } } } 

and model 'gamme' :

public class gamme     {         [key]         [column(order = 0)]         [foreignkey("profile_ga")]         public string id_gamme { get; set; }         [key]         [column(order = 1)]         [foreignkey("poste")]         public string id_poste { get; set; }         public int position { get; set; }         public int nbr_passage { get; set; }         public string last_posts { get; set; }         public string next_posts { get; set; }          public virtual poste poste { get; set; }         public virtual profile_ga profile_ga { get; set; }      } } 

replace "<%: html.editorfor(x=>x.yourgammemodel.nbr_passage)%>" code "<%: html.textbox("nbr_passage",(model != null && model.yourgammemodel != null) ? model.yourgammemodel.nbr_passage : 0) %>"

and in post method include example

[httppost] public actionresult save (flowviewmodel flowviewmodel, fromcollection form) { //get value using formcollection int nbr_passage = (int)form["nbr_passage"];  } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -