2016-05-12 7 views
0

私はフィルタとニュース記事のリストを表示する新しいスタートページに取り組んでいます。各ニュースポストと各ニュースリストは、複数のビジネスエリアでタグ付けすることができます。フォームの値をコントローラに取得するには

  • 管理者によって変更することができnewslistの設定:

    newslistはに従ってニュースを含んでいます。

  • 次に、ページのフィルタフォームでフィルタリングします。
  • フィルタが空でもユーザーがログインしている場合は、ユーザーの設定でフィルタリングされます。

ビューIndexSecondがロードされると、フィルタはそのnewslistに応じて選択可能なビジネス領域を取得します。私の問題は、選択したビジネスエリアをEditorForからmodel.filteredBAsに、どのようにしてIndexSecondFilteredに渡すのかを知りません。

IndexSecondFilteredのブレークポイントに来ると、modelは常にnullです。ビューで

は、私は同僚からの助けを得

@model Slussen.BLL.Models.PostFilterListModel 
... 
@using (Html.BeginForm("IndexSecondFiltered", "Home", new { model = model })) 
{ 
     @Html.HiddenFor(model => model.filteredBAs) 
     @Html.ValidationSummary(true, "", new { @class = "text-danger" }) 
     <div class="form-group"> 
      <div class="col-sm-2">Business area</div> 
      <div class="col-md-10"> 
       @Html.EditorFor(model => Model.newslistModel.BusinessAreas, 
             new { htmlAttributes = new { @class = "form-control" } }) 
      </div> 
     </div> 

     <div class="form-group"> 
      <div class="col-md-offset-2 col-md-10"> 
       <input type="submit" value="Go" class="btn btn-primary orange" /> 
      </div> 
     </div>     
} 

にHomeControllerで

public ActionResult IndexSecond() 
{ 
    //Known user? 
    int? uo = null; 
    if (User.Identity.IsAuthenticated) 
     uo = CurrentUser.UserOrganization.Id; 

    return View(
      _queryDispatcher.Execute<PostFilterListModel>(
       new GetFilteredNewsListById(1, uo, "", 1, 
       new System.Collections.Generic.List<int>(), 
       new System.Collections.Generic.List<int>()))); 
} 

[HttpPost] 
public ActionResult IndexSecondFiltered(PostFilterListModel model) 
{ 
    //Known user? 
    int? uo = null; 
    if (User.Identity.IsAuthenticated) 
     uo = CurrentUser.UserOrganization.Id; 

    return View(
      _queryDispatcher.Execute<PostFilterListModel>(
       new GetFilteredNewsListById(1, uo, "", 1, 
       new System.Collections.Generic.List<int>(), model.filteredBAs))); 
} 
+0

あなたは 'BusinessAreas'エディタのためのあなたのコードを表示することができますテンプレート? –

答えて

0

をIndexSecond。

[HttpPost] ActionResult IndexSecondFilteredはまったく必要ありませんでした。私はモデルがIsSelected-状況と一緒にコントローラに渡されたこの

@using (Html.BeginForm("IndexSecond", "Home")) 

この

@using (Html.BeginForm("IndexSecondFiltered", "Home"), new { model = model }) 

を交換した場合

関連する問題