[英]How to pass value of textbox to a method in controller?
在Angularjs中,我嘗試將值從文本框傳遞到控制器中編寫的方法,如下所示
<input type="text" ng-blur="isExists(this.value)">
在我的控制器內
$scope.isExists = function (theValue) {
alert(theValue);
};
它不起作用。
<input type="text" ng-model="username" ng-blur="isExists()">
並在控制器內
$scope.isExists = function () {
alert($scope.username); // returns undefined
};
如何將值從ng-blur
傳遞到Controller中的方法?
為什么在文本框中看不到該value
?
<input type="text" ng-model="username" ng-blur="isExists()">
如果<input type="text"
Try2不應返回undefined
至少包含一個字符。
您可以在html頁面上附加{{username}},僅用於調試目的,以確保其綁定正確。
<input type="text" name="userId" id="txtid" />
<script type="text/javascript">
$(document).ready(function () {
$('#txtid').blur(function () {
debugger;
var id = $('#txtid').val();
window.location = "/Home/CreateSupplier/?userid=" + id;
});
});
</script>
在控制器中
public ActionResult CreateSupplier(string userid)
{
if (userid != null)
{
return Content("Received Username:" + userid);
}
return View(thesupplierList);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.