How to use parametres from differents models in the same View in ASP MVC 3

anouar2002
 
on May 14, 2013 04:51 AM
2572 Views

I am developing an ASP .Net MVC 3 application using C# and SQL Server 2005.

I am using also Entity Framework and Code First Method.

I have a partial view that inherit from a Model View 'FlowModelView' because I am using a list from this model.

I want to use parametres from another model 'Gamme'.

When I try this,,,the statement is always underline in Red.

This is the Partial view :
 

<%@  Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MvcApplication2.Models.FlowViewModel.Gamme>" %>

<% using (Html.BeginForm()) { %>
    <%: Html.ValidationSummary(true) %>
    <fieldset class="parametrage">
        <legend>Gestion de Gamme</legend>

        <div><%:Html.Label("Poste :")%><%: Html.DropDownList("SelectedPoste", Model.PostesItems)%></div>


         <div><%:Html.Label("Nombre de Passage :")%><%: Html.EditorFor(Model.Gamme=>Model.Gamme.Nbr_Passage) %></div>

        </fieldset>
         <% } %>

this the FlowViewModel :


public class FlowViewModel
    {

        [Key]
        public string IDv { get; set; }
        [NotMapped]
        public SelectList PostesItems { get; set; }
        //public List<Poste> PostesItems { get; set; }
        public List<Profile_Ga> Profile_GaItems { get; set; }
        public List<Gamme> GaItems { get; set; }

        public int SelectedProfile_Ga { get; set; }

        public int SelectedGamme{ get; set; }

        public int SelectedPoste { get; set; }
    }

and this is the Gamme Model :

namespace MvcApplication2.Models
{
    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; }

    }

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
ashusingh
 
on May 26, 2013 02:52 AM

As i understood that you want to use two different model in one view.So you need to make a common modal which will keep this those different model in this.Otherwise paste your code where you are getting error that particular line.