Javascript Post字段填充邮政编码搜索后为空值

Javascript Post字段填充邮政编码搜索后为空值,javascript,jquery,asp.net,asp.net-mvc-5,unobtrusive-validation,Javascript,Jquery,Asp.net,Asp.net Mvc 5,Unobtrusive Validation,我正在做一个Crud,我遇到了麻烦,因为一些填充了.val()的字段不会出现在帖子中 如果是手动加注,则正常加注 你能帮我吗 链接到ViewModel的视图 @model CRUD.ViewModel.ClienteViewModel @使用(Html.BeginForm)(null,null,FormMethod.Post, 新的{name=“frm”,id=“frm”}) { @Html.AntiForgeryToken() @LabelFor(model=>model.DscEnderec

我正在做一个Crud,我遇到了麻烦,因为一些填充了.val()的字段不会出现在帖子中

如果是手动加注,则正常加注

你能帮我吗

链接到ViewModel的视图

@model CRUD.ViewModel.ClienteViewModel
@使用(Html.BeginForm)(null,null,FormMethod.Post,
新的{name=“frm”,id=“frm”})
{
@Html.AntiForgeryToken()
@LabelFor(model=>model.DscEndereco,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.DscEndereco,new{htmlAttributes=new{@class=“form control”}})
@Html.ValidationMessageFor(model=>model.DscEndereco,“,new{@class=“text danger”})
@LabelFor(model=>model.NomBairro,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.NomBairro,new{htmlAttributes=new{@class=“form control”}})
@Html.ValidationMessageFor(model=>model.NomBairro,”,new{@class=“text danger”,@id=“valbairro”})
@LabelFor(model=>model.Cep,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.Cep,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.Cep,“,new{@class=“text danger”})
@LabelFor(model=>model.CidadeId,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.CidadeId,new{htmlAttributes=new{@class=“form control”}})
@Html.ValidationMessageFor(model=>model.CidadeId,“,new{@class=“text danger”})
@LabelFor(model=>model.UF,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.UF,new{htmlAttributes=new{@class=“form control”})
@*@Html.ValidationMessageFor(model=>model.UF,“,new{@class=“text danger”})*@
}
@节脚本{
@Scripts.Render(“~/bundles/jqueryval”)
}
$('#Cep')。关于(“更改”,函数(e){
e、 预防默认值();
var cep=$('#cep').val().replace(“-”,”);
if($('#hdnCep').val()==cep)
{
返回false;
}
美元(“#dscentdereco”).val(“”);
美元(“#NomBairro”).val(“”);
美元(“#CidadeId”).val(“”);
$(“#Estado”).val(“”);
$.getJSON(“http://cep.republicavirtual.com.br/web_cep.php?cep=“+cep+”&formato=json“,{},函数(数据){
如果(data.resultado_txt=“sucesso-cep completo”){
$('hdnCep').val(cep);
$('DscEndereco').val(data.tipo_logradouro+''+data.logradouro);
$('NomBairro').val(data.bairro);
$('CidadeId').val(data.cidade);
$('#UF').val(data.UF);
}
});
});
视图模型

使用系统;
使用System.Collections.Generic;
使用System.ComponentModel.DataAnnotations;
使用System.Linq;
使用System.Web;
命名空间CRUD.ViewModel
{
公共类客户端视图模型
{
[关键]
公共int客户端ID{get;set;}
[必需]
[显示(Name=“Endereço”)]
公共字符串DscEndereco{get;set;}
[必需]
[显示(Name=“Bairro”)]
公共字符串NomBairro{get;set;}
[必需]
[显示(Name=“CEP”)]
公共字符串Cep{get;set;}
[必需]
[显示(Name=“Cidade”)]
公共字符串CidadeId{get;set;}
公共虚拟Crud.Models.Cidade Cidade{get;set;}
[必需]
公共字符串UF{get;set;}
[必需]
公共字符串Cnpj{get;set;}
}
}
控制器

//POST:clients/Create
//若要防止套印攻击,请启用要绑定到的特定属性,例如
//更多详细信息请参见http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
公共操作结果创建(ClientViewModel ClientViewModel)
{
if(ModelState.IsValid)
{
}

代码太多了。您是否已经缩小了可能发生错误的范围?我建议您不要将代码片段用于无法在此页面上运行的代码。它仅适用于HTML/CSS/JavaScript。大家好。我发现了字段不在POST中的原因。Jquery“已禁用”不发送字段。我改为只读,效果很好。谢谢大家!代码太多了。您是否已经缩小了可能发生错误的范围?我建议您。不要使用代码片段来编写无法在此页面上运行的代码。它只适用于HTML/CSS/JavaScript。大家好。我发现了错误的原因字段不在POST中。Jquery“disabled”不发送字段。我改为只读,效果很好。谢谢大家!