0
我沒有用過單選按鈕,我是MVC的新手。沒有在mvc中獲得Radibutton值
我試圖從視圖中獲取所選單選按鈕的值到控制器Post方法。所有其他的元素值都在期待單選按鈕。他們總是返回false
這裏是我的代碼
VIEW
<label for="first" class="col-sm-3 control-label">Patient Name:</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="first" placeholder="First" name="FirstName">
</div>
<div class="col-sm-2">
<input type="text" class="form-control" id="middle" placeholder="Middle" name="MiddleName">
</div>
<div class="col-sm-3">
<input type="text" class="form-control" id="last" placeholder="Last" name="LastName">
</div>
<div class="col-sm-1"></div>
</div>
<div class="form-group">
<label for="month" class="col-sm-3 control-label">DOB:</label>
<div class="col-sm-2">
@Html.DropDownList("MonthofBirth", Acc.Web_Code.viewmodels.Calendar.MonthsSelectList, "Month", new { @class = "form-control", name = "month", id = "month" })
</div>
<div class="col-sm-1">
@Html.DropDownList("DayofBirth", Acc.Web_Code.viewmodels.Calendar.DaysSelectList, "Day", new { @class = "form-control", name = "day", id = "day" })
</div>
<label class="radio-inline">
<input type="radio" name="Gender" id="male" value="Male"> Male
</label>
<label class="radio-inline">
<input type="radio" name="Gender" id="female" value="Female"> Female
</label>
POST方法
public ActionResult AddNewPatient(AddPView objAddPView)
和我的模型是
public class AddPView
{
[Required]
public string FirstName { get; set; }
public string MiddleName { get; set; }
[Required]
public string LastName { get; set; }
public bool Gender { get; set; }
[Required]
public string YearofBirth { get; set; }
[Required]
public string MonthofBirth { get; set; }
[Required]
public string DayofBirth { get; set; }
[Required]
public string Address1 { get; set; }
[Required]
public string City { get; set; }
[Required]
public string State { get; set; }
public string Zip { get; set; }
[Required]
public string Phone { get; set; }
}
嘗試了很多視野中的變化,但每件事情都會返回false
如何在地球上解決這個問題,OP? –
你能告訴我什麼是'ChangeType.Change'和'ChangeType.New',因爲我不能理解這一點。 @ Codeman01101001 –
@ user3665063,只要忽略它 - 它的完整垃圾並與您的問題無關 –