私はASP.net MVC5で初心者です、私の問題はこれです:データバインド:「可能System.String」の名前のプロパティが含まれていません「numeroGuia」
私は部分図「AgregaGuia」を作成しています、ここではまだ "fechaRecepcionGuia"を持たない行のTblGuiasモデルにクエリを作成します。これらのガイドはコンボボックスに入れられ、これを選択するとそのガイドのすべてのテキストボックスが塗りつぶされます。しかし、アプリケーションを実行すると、次のエラーが生成されました。DataBinding: 'System.String'に 'numeroGuia'という名前のプロパティが含まれていません。
誰でも私を助けてくれますか?
これは私のモデルである:
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);
}
}
と、次のように私の見解は以下のとおりです:
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; }
}
これは私のコントローラである
@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>