0

C# と SQL Server 2005 を使用して ASP .Net MVC 3 アプリケーションを開発しています。

Entity Framework と Code First Method も使用しています。

このモデルのリストを使用しているため、モデル ビュー 'FlowModelView' から継承する部分ビューがあります。

別のモデル「Gamme」のパラメータを使用したいです。

これを試すと、、、ステートメントは常に赤で下線が引かれます。

これは部分的なビューです:

<%@  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>
         <% } %> 

これは 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; }
    }

そしてこれがゲームモデルです:

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; }

    }
and this the controller but contains some errors :


  public class AnouarController : Controller
    {



        //
        // GET: /Anouar/

         public ActionResult Gestion()
         {
            var model = new FlowViewModel()
            { YourGammeModel = new Gamme(){

        public string ID_Gamme { get; set; }

        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; }

            }};

             return PartialView();

         }




    }
4

4 に答える 4

1

この行の問題:

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

あなたはラムダ式を書きましたが、 g が型の場所Model.Gamme=>Model.Gamme.Nbr_Passageを書くべきですg=>g.Nbr_PassageGamme

ビューのタイプを次のように変更します。

<%@ Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MvcApplication2.Models.Ga‌​mme>" %>
于 2013-05-14T09:11:04.513 に答える
1

昨日お送りいただいたコードによると、Gestion を別のビュー内でパーシャルとしてレンダリングしているため、このコントローラー アクションは実際にはヒットしません。Index.aspxと書いてあるところを変える必要があります

Html.RenderPartial("Gestion")

Html.RenderAction("Gestion", "Anouar", Model)

コントローラーのアクションを次のように変更します。

public ActionResult Gestion(FlowViewModel model)
{
    model.YourGammeModel = new Gamme();

    return PartialView(model);
 }
于 2013-05-14T13:22:29.417 に答える
1

ビューページで以下を使用して確認してください

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

Gammeまたは、モデルのみが必要な場合は、次を使用する必要があります

 <%@  Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MvcApplication2.Models.Gamme>" %>
于 2013-05-14T09:07:13.577 に答える