我想将从控制器操作返回的字符串绑定到视图上的文本框。任何帮助将不胜感激。这是我的控制器代码:
public ActionResult Display(ViewModel.CompanyViewModel entityViewModel)
{
int size=3;
string password="0123456789";
Random rnd = new Random();
System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(size);
for (int i = 1; i <= size; i++)
{
stringBuilder.Append(password[rnd.Next(password.Length)]);
}
Managers.CompanyManager companyManager = new Managers.CompanyManager();
entityViewModel.SequentialId = stringBuilder.ToString();
int isCustomerIDExists = companyManager.isExistsSequentialID(entityViewModel);
if (isCustomerIDExists > 0)
{
for (int i = 1; i <= size; i++)
{
stringBuilder.Append(password[rnd.Next(password.Length)]);
}
}
string str = stringBuilder.ToString();
return Json(new { str = str }, JsonRequestBehavior.AllowGet);
}
这是我的 View-Javascript 代码:
<script type="text/javascript">
function btnNextAvailable_OnClick() {
$("#nextAvailableButtonClick.val('true')");
var mode = $.hash.getValue("m");
var urlInsert = '@Url.Action("Display")';
$.getJSON(urlInsert, function () {
});
document.getElementById("SequentialId").value = '@Url.Action("Display")';
}
</script>
我想将从控制器操作返回的字符串 str 绑定到视图上的文本框“SequentialID”。
这是我查看的代码:
function btnNextAvailable_OnClick() {
$("#nextAvailableButtonClick.val('true')");
var mode = $.hash.getValue("m");
var urlInsert = '@Url.Action("Display")';
$.get(urlInsert, function () {
})
$.ajax({
type: "POST",
url: '/CompanyController/Display',
async: false,
data: {},
dataType: "json",
success: (function (data) {
$('#SequentialId').value(data);
}),
error: (function () {
alert("error");
})
});
}