2017-04-04 15 views
0

これはマイビューです。フォームMVCを送信中にコントローラでDropDownの値を取得

@using (Html.BeginForm("uploadimage", 
          "PatientDocumentsMain", 
          FormMethod.Post, 
          new { @Area = "PatientDocument", enctype = 
          "multipart/form-data" })) 
     { 
     <table cellspacing="0" cellpadding="0" class="table table- 
      striped"> 
      <tr> 
      <td> 
       Document Name:<span class="spnError">*</span> 
      </td> 
      <td> 
       <input type="text" id="txtDocumentName" name="DocName" 
       class="required form-control" /> 
      </td> 
      </tr> 
      <tr> 
      <td class="tdEditDoc"> 
      <span>Document Type:</span><span class="spnError">*</span> 
      </td> 
      <td id="tdDocumentCategory">     
      @Html.DropDownList("ddlDocumentCategory", null, new { @id = "", 
           @onchange = "AddCategory();", @class = 
           "required form-control", @name= "DocType" }) 
      </td> 
      </tr> 
      <tr> 
      <td class="tdEditDoc"> 
       <span>Date:</span><span class="spnError">*</span> 
      </td> 
      <td> 
       <input type="text" id="txtPatientDocumentDate" class="Date 
       required IsDate form-control" name="DocDate" /> 
      </td> 
      </tr> 
      <tr> 
      <td class="tdEditDoc" style="height: 25px;"> 
       <span>Confidental:</span> 
      </td> 
      <td> 
       <input type="checkbox" id="chkPatientDocumentIsConfedential" 
       /> 
      </td> 
      </tr> 
      <tr> 
       <td class="tdEditDoc" style="vertical-align: top"> 
       Comments: 
       </td> 
       <td> 
       <textarea id="txtPatientDocumentComments" name="comments" 
       style="margin-right: 15px; width: 245px; height: 69px; 
       border-width: 1px; border-color: #c4c4c4;resize:none" 
       class="form-control"> 
       </textarea> 
       </td> 
       </tr> 
      </table> 
    <input type="file" name="file" id="file" title="Upload file(s)" /> 
} 

私は私が(チェックまたはしない)チェックボックスの値を取得することができますどのようにドロップダウンvalue.Plusを除く他のすべてのパラメータを取得しています。このコントローラに

public void uploadimage(string DocName, string DocType, string DocDate, string d, string comments, HttpPostedFileBase file) 
    { 

    } 

をこのフォームを送信しています。私はモデルを使用していないし、それなしでやりたい

+1

フィールドの名前です。 –

+0

は使用できません。 FormValuesはどのように使用できますか? –

+0

ActionMethod内のパラメータを に置き換えます。 'public void uploadImage(FormCollection fomr)...'キー/値の辞書です。 –

答えて

0

最初のパラメータは、あなたのポストactionMethod内そんなに変数を作成しているなぜ、私はFormValuesまたはモデルを使用することをお勧めし

@Html.DropDownList("DocType", null, new { @id = "", @onchange = "AddCategory();", @class = "required form-control" }) 
0

null値のドロップダウンバインド?

@Html.DropDownList("ddlDocumentCategory", null, new { @id = "", @onchange = "AddCategory();", @class = "required form-control", @name= "DocType" }) 

また、入力フィールドの名前が文字列パラメータと同じであることを確認してください。

参考リンク How to submit your form in asp.net mvc

+0

'@ name =" DocType "'は何もしません(これは幸いなことに(それはそれです。) 'name'属性は変更されません) –

+0

あなたは正しいです。 。しかし、私はちょうど質問に記載されている同じ行をコピーします.... –

+0

あなたの答えのポイントは何ですか? –

関連する問題