【发布时间】:2016-05-26 18:34:25
【问题描述】:
我是 ASP.net MVC5 的新手,我的问题是:
我正在创建一个局部视图“Agregaguia”,其中我对尚未拥有“FechareCepcionGuia”的行的TBLGuias模型进行了查询,这些指南填写在组合框中,并选择此指南填充所有文本框在那个视图中。但是,在运行应用程序时,它会产生以下错误:DataBinding : 'System.String' does not Contain a property with name 'numeroGuia'。
谁能帮帮我?
这是我的模型:
public partial class TblGuias
{
public TblGuias()
{
this.TblFactIC = new HashSet<TblFactIC>();
}
public string numeroGuia { get; set; }
public string companiaEnvios { get; set; }
public string destino { get; set; }
public decimal pesoGuia { get; set; }
public System.DateTime fechaEnvioGuia { get; set; }
public Nullable<System.DateTime> fechaRecepcionGuia { get; set; }
public string comprobante { get; set; }
public virtual ICollection<TblFactIC> TblFactIC { get; set; }
}
这是我的控制器:
public class vueInveEntrsController : Controller
{
public ActionResult AgregaGuia()
{
ViewData["guia"] = new SelectList(db.TblGuias.Where(g => g.fechaRecepcionGuia == null).Select((g => g.numeroGuia)),"numeroGuia", "companiaEnvios","destino","pesoGuia","fechaEnvioGuia");
return PartialView(db.TblGuias.ToList());
}
[HttpPost]
public ActionResult Action(string numero)
{
var query = from c in db.TblGuias
where c.numeroGuia == numero
select c;
return Json(query);
}
}
我的看法如下:
@using (@Html.BeginForm("Action", "vueInveEntrs", FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="form-group">
@Html.Label("Seleccione Guia", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("numero", (SelectList)ViewData["guia"], new { onchange = "Action(this.value);", @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.Label("Compañia Envios", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBox("transporte", null, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.Label("Destino", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBox("destino", null, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.Label("Peso", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBox("peso", null, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.Label("Fecha Envio", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBox("fechaenvio", null, new { @class = "form-control" })
</div>
</div>
}
<script type="text/javascript">
function Action(numero) {
$.ajax({
url: '@Url.Action("Action", "vueInveEntrs")',
type: "POST",
data: { "numero": numero },
"success": function (data) {
if (data != null) {
var vdata = data;
$("#transporte").val(vdata[0].companiaEnvios);
$("#destino").val(vdata[0].destino);
$("#peso").val(vdata[0].pesoGuia);
$("#fechaenvio").val(vdata[0].fechaEnvioGuia);
}
}
});
}
</script>
【问题讨论】:
标签: javascript asp.net-mvc-5 json.net