2012-02-14 5 views
2

私はMVC 3が新しく、問題が残っています。メインレイアウトは次のようになります。MVC 3マルチフォームモデルを辞書に渡す

<body> 
<div id="conteiner_body"> 
    <div id="conteiner_main"> 
     <div id="container_top"> 
      @{ Html.RenderPartial("Basket"); } 
      @{ Html.RenderPartial("MenuTop"); } 
     </div> 
     <div id="left_side_border"> 
      <div id="left_side"> 
       @{ Html.RenderPartial("SearchBox"); } 
       @{ Html.RenderAction("Index", "LeftMenu"); } 
      </div> 
     </div> 
     <div id="content"> 
      @RenderBody() 
     </div> 
     @{ Html.RenderPartial("Footer"); } 
    </div> 
</div> 
</body> 

ページに3つのフォームがあります。第MenuTopビューである:

@model Models.LogOnModel 
<div id="conteiner_menu_top"> 
    <div id="menu_top"> 
     <div id="login"> 
      <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> 
      <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> 

      @{ 
       using (Html.BeginForm("LogOn", "Account")) 
       { 
        @Html.TextBoxFor(m => m.UserName) 
        @Html.PasswordFor(m => m.Password) 
        @Html.CheckBoxFor(m => m.RememberMe) 
        <input type="submit" value="Login" /> 
        <input type="button" value="Registr" onclick="document.location.href = '/Account/Register'" /> 
       } 
      } 
     </div> 
    </div> 
</div> 

第二のサーチである:

@using (Html.BeginForm("Search", "SearchBox")) 
{ 
<div id="search_box"> 
    <h2>Search</h2> 
     <input name="searchWord" class="text" type="text" /> 
     <a href="rozsirene_vyhledavani">Advanced</a> 
     <input class="submit" type="submit" value="Search" /> 
</div> 

もちろんコンテキストに応じて変化RenderBodyでフォーム、。 RenderBody()からフォームを投稿すると問題が発生します。登録、私は次のエラー受け取る:

The model item passed into the dictionary is of type 'Models.RegisterModel', but this dictionary requires a model item of type 'Models.LogOnModel'.

を私はMenuTopとサーチに、独自の辞書を追加しようとしました:

Html.RenderPartial("MenuTop", new ViewDataDictionary(Models.LogOnModel)) 
Html.RenderPartial("SearchBox", new ViewDataDictionary(IEnumerable<Product>)) 

しかし、この場合には、私はエラーを次取得:

CS0119: 'Models.LogOnModel' is a 'type', which is not valid in the given context

誰にも何のアイデアは、どのようにこれを解決するには?どうもありがとう。

答えて

1
@{Html.RenderPartial("MenuTop", new Models.LogOnModel());} 
@{Html.RenderPartial("SearchBox", Enumerable.Empty<Product>());} 
+0

ありがとうございます。 – Andree

関連する問題