我正在使用post方法,其中我正在將文本框的值發佈到數據庫,爲此我正在執行所有必要的步驟,但是在該post方法中,我的模型爲null。找到下面的代碼, 我簡單的控制器mvc4中的模型值爲null
[HttpPost]
public ActionResult Index(QuestionBankModel question)
{
return View();
}
我的模型
public class QuestionBankModel
{
public string question { get; set; }
}
我查看
@model OnlinePariksha.Models.QuestionBankModel
@{
var CustomerInfo = (OnlinePariksha.Models.UserLoginModel)Session["UserInfo"];
}
@{
ViewBag.Title = "Index";
}
@{
Layout = "~/Views/Shared/Admin.cshtml";
}
@using (Html.BeginForm("Index", "AdminDashboard", FormMethod.Post))
{
<div id="questionsDiv" style="width:100%; display:none;">
<div style="width:200px">
<table style="width:100%">
<tr>
<td><span><b>Question:</b></span></td>
<td>
@Html.TextBox(Model.question, new Dictionary<string, object> { { "class", "textboxUploadField" } })
</td>
</tr>
</table>
</div>
<div class="clear"></div>
<div>
<input type="submit" class="sucessBtn1" value="Save" />
</div>
</div>
}
我錯過了什麼?
所以QuestionBankModel有1個屬性:問題。在HttpPost上觸發Index操作時,該問題的值爲空? – Minh