2017-07-04 28 views
0

我需要在點擊插入按鈕時檢查是否所有字段都已填充。 這是我的看法:.NET中的驗證MVC

<body> 

    <form name="form1"> 
     <h2>MEDICATION</h2> 
     <div class="med"> 
      <pre>   
<label>Patient code</label>  <input type="text" id="pat" name="ptcode" size="25" value="" />        <label>ICD10</label> <input style="width:85px;height:30px;" type="text" name="icd10" value="">&nbsp;&nbsp;&nbsp;&nbsp;<button style="height:30px;width:59px;" name="search" onclick="openicd()";>search</button><br /> 
<label>Medication</label>   @Html.DropDownListFor(Model => Model.medication, Model.medication,"Select Medication", new { style = "width:200px; height :30px" }) <button style="height:30px;"onclick="openmedication()";>search</button>   Prescription Date <input type="date" class="sizetestdate" name="testdate" style="width:140px;height:30px;" value=""> 

<label>Strength</label>   @Html.DropDownListFor(Model => Model.strength, Model.strength, "Select Strength", new { style = "width:200px; height :30px" })     Start Date   <input type="date" class="sizetestdate" name="testdate" style="width:140px;height:30px;" value=""> End Date <input type="date" class="sizetestdate" name="testdate" style="width:140px;height:30px;" value=""><br />       
<label>Form</label>    @Html.DropDownListFor(Model => Model.form, Model.form, "Select form", new { style = "width:200px; height :30px" })     Renewal Date  <input type="date" class="sizetestdate" name="testdate" style="width:140px;height:30px;" value=""><label> Days Supply</label> <input type="text" style="width:85px;height:30px;" name="supply" value=""> <br />   
<label>Route</label>    @Html.DropDownListFor(Model => Model.route, Model.route, "Select route", new { style = "width:200px; height :30px" })     <label>Pharmacy</label>   @Html.DropDownListFor(Model => Model.pharmacy, Model.pharmacy, "Select Pharmacy", new { style = "width:200px; height :30px" })<br />      
<label>Dose</label>    @Html.DropDownListFor(Model => Model.dosage, Model.dosage, "Select Dose", new { style = "width:200px; height :30px" })      
</pre> 
     </div> 
    </form> 
    <hr /> 
    <div class="wrapper"> 
     <button class="button" style="height:30px;" id="a" >Insert</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button class="button" style="height:30px;" id="b">Update</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button class="button" style="height:30px;" id="c">Delete</button> 

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

回答

0

你可以用你的模型進行驗證

public class Example { 

    public int id { get; set; } 

    [Required] 
    public string name { get; set; } 
} 

view more - Microsoft Docs

+0

雖然這種聯繫可以回答這個問題,這是更好在此包括答案的基本部分並提供參考鏈接ENCE。如果鏈接頁面更改,則僅鏈接答案可能會失效。 – Dwhitz

+0

@Dwhitz Ok thx,編輯 – wtMaxim

0
The best way is adding model Validations in Models 
i don't know how your model look like assuming 

public class Meditation 
{ 
    [Required] 
    public int id{get;set} 

    [Required] 
    public int name{get;set;} 



} 
using System.ComponentModel.DataAnnotations; should be added 

or you can simply use required in form 

<input type="text" style="width:85px;height:30px;" name="supply" value="" required> 

    @Html.DropDownListFor(Model => Model.dosage, Model.dosage, "Select Dose", new { style = "width:200px; height :30px", @required="true"})