大家好我目前有一個網站,有一個按鈕和一些JavaScript,創建一個加載外觀,然後運行這個動作結果。我想向actionresult添加參數,但不知道如何去做。謝謝!這裏是我的代碼 控制器:將參數添加到Razor中的URL.Action
[HttpPost]
public ActionResult PostMethod(string MyText)
{
System.Threading.Thread.Sleep(5000);
return Json("And were done");
}
查看:
<input type="text" name="MyTextBlock"/>
<p id="PID">
Default message from declarative syntax.
</p>
<div id="divLoading" style="margin: 0px; padding: 0px; position: fixed; right: 0px;
top: 0px; width: 100%; height: 100%; background-color: #666666; z-index: 30001;
opacity: .8; filter: alpha(opacity=70);display:none" >
<p style="position: absolute; top: 30%; left: 45%; color: White;" align="center">
<img src="../../Content/themes/base/images/ajax-loading.gif"><br />
Loading, please wait...
</p>
</div>
<button onclick="JavascriptFunction();">HTTPPost Button</button>
<script type="text/javascript" language="javascript">
function JavascriptFunction() {
var url = '@Url.Action("PostMethod", "MyTextBlock", new { MyText = "john" })';
$("#divLoading").show();
$.post(url, null,
function (data) {
$("#PID")[0].innerHTML = data;
$("#divLoading").hide();
});
}
</script>
我想要做的就是通過MyTextBox到的PostMethod使用它作爲MYTEXT。其他一些例子,我看到硬編碼的值,我希望它來自文本框。任何幫助是極大的讚賞。謝謝!
我該如何添加多個控件? – Badmiral