![](/img/trans.png)
[英]Bizzare behavior of MVC Action/RenderAction, ajax post, and Partial Views
[英]MVC ajax renderaction partial
我是一個小人物,所以我的問題很簡單,但由於這個原因,我已經呆了兩天。 因此,我有一個html表單,客戶可以在其中保留其聯系數據,例如
<form>
<input id="name" type="text" placeholder="Имя"><br>
<input id="Email" type="text" placeholder="E-mail"><br>
<input id="phonenumber" type="text" placeholder="Телефон"><br>
<input id="adress" type="text" placeholder="Адрес"><br>
<textarea id="comment" placeholder="Комментарий"></textarea>
<button id="submit" class="send" value="Отправить">Отправить</button>
</form>
我希望能在我的控制器上找到它
[HttpPost]
public ActionResult setupRequest(AirconditioningSetupRequestModel model)
{
//model goes to DB
return View();
}
我如何用AJAX處理呢? 請幫幫我。
您可以設置表單的方法和操作屬性
方法-動作后-控制器/ setupRequest
由於您具有表單和輸入提交,因此這將觸發您在MVC控制器中的操作。 但是,要為模型AirconditionSetupRequestModel中使用的輸入元素使用默認模型綁定集名稱屬性,該屬性將在表單提交時在服務器端進行綁定。
使用類似這樣的東西:string name = Request.Form [“ name”]; 等等...
//Save Click Function
var Name=$("#name").val();
var Email=$("#Email").val();
$.ajax({
url:'ControllerName/Save',
type:'POST',
data:{ContName: Name, ContEmail:Email}
success: function(data)
{
//data return from controller
}
});
public ActionResult Save(string ContName, string ContEmail)
{
//Save to DB
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.