在ajax调用之后,UI中没有填充任何值 [英] No values are populated in UI after ajax call
问题描述
我的应用程序包含两个文本框和一个操作链接。在单击操作链接时,将在文本框中填充值。值显示在UI中。但是,这些不与模型绑定并显示验证错误消息,尽管文本框具有值。请告诉我如何避免这些错误消息 My application contains two text boxes and one action link. On click of action link, values gets populated in text boxes. Values are showing in UI. But, those are not bind with model and showing validation error messages, though the text boxes have values. Please let me know how to avoid those error messages 这篇关于在ajax调用之后,UI中没有填充任何值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
注意:由于模型和视图中有几个字段,我在这里列出的很少。
查看:
<前lang =Javascript>< div id = divNames>
@ Html.TextBoxFor(model => model.Name, new {id = txtFirstName,maxlength = 30 })
@ Html.TextBoxFor(model => model.LastName, new {id = txtLastName,maxlength = 30})< / div >
@ Html.ActionLink( 搜索, , , null , new {id = 温泉n> btnSearch)
$( #btnSearch)。click( function (e){
var url = ' @ Url.Content(〜/)' + signature / GetDetails;
var idnumber = $( #txtDocumentNo 跨度>)VAL();
$ .ajax({
url:url,
data:$(' #frm1')。serialize(),
类型:' GET' ,
成功:功能(数据){
var url = ' @ Url.Content(〜/)' + signature / GetDetails;
$(' #divNames')。load(url2 + ' #divNames')
}
});
return false ;
});
控制器:
public ActionResult GetDetails(用户用户)
{
user.Name = 名字< /跨度>;
user.LastName = 姓氏;
return 查看( 注册,用户);
}
型号:
public class BRUser
{
public string 名称{ get ; set ; }
public string LastName { get 跨度>; set ; }
}
( #btnSearch)。click( function (e){
var url = ' @ Url.Content(〜/)' + signature / GetDetails;
var idnumber =
( #txtDocumentNo)。val();
.ajax({
url:url,
data:
Note: As there are several fields in model and view, I listed few here.
View:
<div id="divNames">
@Html.TextBoxFor(model => model.Name, new { id = "txtFirstName", maxlength = "30" })
@Html.TextBoxFor(model => model.LastName, new { id = "txtLastName", maxlength = "30" })</div>
@Html.ActionLink("Search", "", "", null, new { id = "btnSearch")
$("#btnSearch").click(function (e) {
var url = '@Url.Content("~/")' + "signature/GetDetails";
var idnumber = $("#txtDocumentNo").val();
$.ajax({
url: url,
data: $('#frm1').serialize(),
type: 'GET',
success: function (data) {
var url = '@Url.Content("~/")' + "signature/GetDetails";
$('#divNames').load(url2 + ' #divNames')
}
});
return false;
});
Controller:
public ActionResult GetDetails(User user)
{
user.Name = "first name";
user.LastName = "last name";
return View("Registration", user);
}
Model:
public class BRUser
{
public string Name { get; set; }
public string LastName { get; set; }
}
("#btnSearch").click(function (e) {
var url = '@Url.Content("~/")' + "signature/GetDetails";
var idnumber =
("#txtDocumentNo").val();
.ajax({
url: url,
data: