2017-04-04 50 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)" /> 
} 

我提交這份表格到該控制器

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

    } 

我得到不同的下拉value.Plus所有其它參數我怎樣才能得到複選框的值(選中與否)。我沒有使用任何模型,並希望沒有它。

+1

你爲什麼您的文章actionMethod內創造了這麼多變量的名字,我會建議使用FormValues或模型。 –

+0

不能使用模型。我怎樣才能使用FormValues? –

+0

將ActionMethod中的參數替換爲 'public void uploadImage(FormCollection fomr)...'它是一個鍵/值字典。 –

回答

0

第一個參數是場

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

下拉框用空值綁定?

@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

那麼你的答案的重點是什麼? –

相關問題