2016-09-21 6 views
1

モーダルブートストラップ内に部分的なビューを作成して、フィールド値の編集ビューでテーブルに値を追加できるようにすることができますか?編集ビュー内でパーシャルビューを作成するにはどうすればよいですか?

私の部分図を作成

@model MVCLayout.Models.Table2 

    <p> 
     @using (Html.BeginForm()) 
     { 
      @Html.AntiForgeryToken() 
      @Html.ValidationSummary(true) 

      <div class="form-group"> 
       @Html.Label("Cargo: ", new { style = "width:160px" }) 
       @Html.TextBoxFor(model => model.ID, new { style = "width:200px" }) 
      </div> 
      <br/> 

      <div class="form-group"> 
       @Html.Label("Percentual: ", new { style = "width:160px" }) 
       @Html.TextBoxFor(model => model.Name, new { style = "width:200px" }) 
      </div> 
      <br/> 

      <div class="form-group"> 
       @Html.Label("Serviço: ", new { style = "width:160px" }) 
       @Html.TextBoxFor(model => model.Work, new { style = "width:200px" }) 
      </div> 
      <br/> 

      <p> 
       <input type="submit" value="Save" /> 
      </p> 

     } 

     </p> 

私の編集ビュー

<html> 
<body> 
@model MVCLayout.Models.Table1 

@{ 
    ViewBag.Title = "Edit"; 
} 
    <div id="signup"> 
     <div class="rontainer"> 
      <div class="header"> 
       <div id="dock"> 
       <br> 
       @using (Html.BeginForm("Edit", "AdmServicos", FormMethod.Post, new { @class = "form-inline" })) 
       { 
        @Html.AntiForgeryToken() 

        <fieldset> 
         <legend>Editar Servios</legend> 
         <br> 
         <div class="form-group"> 

          @Html.Label("Código:", new { style = "width:160px" }) 
          @Html.TextBoxFor(model => model.ID, new { style = "width:55px", @readonly = "readonly" }) 

         <div class="form-group"> 
          @Html.Label("Descrição: ", new { style = "width:160px" }) 
          @Html.TextBoxFor(model => model.Descricao, new { style = "width:550px", @readonly = "readonly" }) 
         </div> 


         </div> 

         <br /> 
         <br /><br /> 
         <p> 
          <input type="submit" value="Salvar" /> 
         </p> 
        </fieldset> 
        <div class="modal fade" id="myModal" role="dialog"> 
         <div class="modal-dialog"> 

          <!-- Modal content--> 
          <div class="modal-content"> 
           <div class="modal-header"> 
            <button type="button" class="close" data-dismiss="modal">&times;</button> 
            <h4 class="modal-title">Modal Header</h4> 
           </div> 
           <div class="modal-body"> 
            @{ 
             Html.RenderPartial("CreateTable2", Model.ID); 
            } 
           </div> 
           <div class="modal-footer"> 
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
           </div> 
          </div> 

         </div> 
        </div> 
             } 
      </div> 
     </div> 
    </div> 
</body> 
</html> 

は、私は部分ビューまたはこれを行うための最善の方法でこれを行うことができますか?

+0

MVCLayout.Models.Table2モデルをロードしたい場所に何らかのダイアログを追加しようとしていますか?またはMVCLayout.Models.Table1の対応するID? – avi

+0

これを行うことができます。 Model2型のオブジェクトをHtml.RenderPartialまたはHtml.Partialのオーバーロードで渡します。部分図がモーダルで表示されます。 –

+0

@SometimesCode私は、Table2のポストではなく、Table1のポストからモデル化するだけです。コントローラーはどうですか?例をもって私を助けることができますか? – Gustavomacedo

答えて

1

以下のようなあなたの表1モデルで表2の種類のプロパティを作成します。

あなたの編集ビューで今すぐ
public class Table1 
{ 
    public Table2 table2 {get; set;} 

//other properties of Table1 Model 
} 

コントローラーのあなたのアクションで今すぐ
<div class="modal-body"> 
     @{ 

     Html.RenderPartial("CreateTable2", Model.table2); 
      } 
     </div> 

public ActionResult Edit(Table1 model) 
{ 
var editPartialViewData = model.table2; 
// Do whatever you want to do with this data 

} 
関連する問題