Ich bin ein Neuling bei ASP.net MVC5, mein Problem ist folgendes:Databinding: ‚System.String‘ enthält keine Eigenschaft mit dem Namen ‚numeroGuia‘
Ich bin eine Teilansicht „AgregaGuia“ zu schaffen, in dem ich eine Abfrage an TblGuias-Modell einer Zeile mache, die noch nicht "fechaRecepcionGuia" hat, werden diese Hilfslinien in einer Combobox gefüllt und wenn diese ausgewählt wird, füllt die Hilfslinie alle Textfelder in dieser Ansicht aus. Beim Ausführen der Anwendung wurde jedoch der folgende Fehler generiert: DataBinding: 'System.String' enthält keine Eigenschaft mit dem Namen 'numeroGuia'.
Könnte mir bitte jemand helfen ??
das ist mein Modell:
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);
}
}
und meiner Meinung nach ist wie folgt:
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; }
}
dies mein Controller ist
@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>