1
以下是我的查看頁面。沒有<form>
標記,當我插入值時,它完全插入。但是,當我插入<form>
標記的值不插入時,調試點指向[HttpGet]
而不是[HttpPost]
。爲了驗證目的,我插入了<form>
標籤。但它似乎是沒有用的..告訴我的解決方案....當我提交表單的值不插入剃鬚刀引擎mvc3?
@model CustMaster.Models.MyAccount
@using CustMaster.Models
@{
ViewBag.Title = "Customer Information";
}
<html>
<head>
<title>Customer Information</title>
<link href="../../style.css" rel="stylesheet">
</head>
<body>
<form action="" id="contact-form" class="form-horizontal">
@using (Html.BeginForm())
{
<table>
<tr>
<td><h3>User Information</h3></td>
</tr>
</table>
<table>
<tr>
<td>
<div class="control-group">
@Html.LabelFor(model => model.CustomerFirstName,
new { @class = "control-label" })
<div class="controls">
@Html.TextBoxFor(model => model.CustomerFirstName,
new { @class = "input-xlarge" })
</div>
</div>
</td>
<td>
<div class="control-group">
@Html.LabelFor(model => model.CustomerMiddleName,
new { @class = "control-label" })
<div class="controls">
@Html.TextBoxFor(model => model.CustomerMiddleName,
new { @class = "input-xlarge" })
</div>
</div>
</td>
</tr>
</table>
<button type="submit">Register</button>
}
@*</form>*@
<script type="text/javascript" src="../../assets/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../../assets/js/jquery.validate.js"></script>
<script type="text/javascript" src="../../assets/js/jquery.validate.min.js"></script>
<script type="text/javascript" src="../../script.js"></script>
</body>
</html>
下面是我的控制器
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(MyAccount myacc)
{
MyAccount ma = new MyAccount();
var objview = ma.GetCustInfo(myacc);
return View();
}
然後如何在@using(Html.BeginForm())中使用id =「contact-form」 – Sham 2012-07-25 15:55:21
只需使用正確的重載:@using(Html.BeginForm(null,null,FormMethod.Post,new { id =「contact-form」}))'。看到我的答案。 – 2012-07-25 15:57:46
現在值被插入到數據庫....是的,我已經注意到,也....它的工作....你好! – Sham 2012-07-26 04:49:30