[英]How to pass value of textbox to a method in controller?
In Angularjs, I'm trying to pass a value from a textbox to method written in controller as below 在Angularjs中,我尝试将值从文本框传递到控制器中编写的方法,如下所示
<input type="text" ng-blur="isExists(this.value)">
and within my controller I have 在我的控制器内
$scope.isExists = function (theValue) {
alert(theValue);
};
It is not working. 它不起作用。
<input type="text" ng-model="username" ng-blur="isExists()">
and within controller 并在控制器内
$scope.isExists = function () {
alert($scope.username); // returns undefined
};
How to pass value from ng-blur
to a method within a Controller? 如何将值从
ng-blur
传递到Controller中的方法?
Any reason why the value
is not seen in the textbox? 为什么在文本框中看不到该
value
?
<input type="text" ng-model="username" ng-blur="isExists()">
Try2 should not return undefined if the <input type="text"
如果
<input type="text"
Try2不应返回undefined
is filled with at least one character. 至少包含一个字符。
You can append {{ username }} on the html page just for debug purporses to make sure it was well binded. 您可以在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>
In controller 在控制器中
public ActionResult CreateSupplier(string userid)
{
if (userid != null)
{
return Content("Received Username:" + userid);
}
return View(thesupplierList);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.