Jquery MVC DropDownList,用于在选择更改另一个下拉列表时填充
资料来源: 我的第一个DropDownList已填充,但更改后,第二个DropDownList仍然为空,我是否认为onchange事件未触发?对不起,我找不到我的错误 _Layout.cshtml: 据我所知(我不懂德语),您遇到服务器端错误,请将控制器更改为:Jquery MVC DropDownList,用于在选择更改另一个下拉列表时填充,jquery,ajax,asp.net-mvc,Jquery,Ajax,Asp.net Mvc,资料来源: 我的第一个DropDownList已填充,但更改后,第二个DropDownList仍然为空,我是否认为onchange事件未触发?对不起,我找不到我的错误 _Layout.cshtml: 据我所知(我不懂德语),您遇到服务器端错误,请将控制器更改为: //your viewmodel for dropdown public class BaureiheViewModel { public int ID {get; set;} public string Symbol
//your viewmodel for dropdown
public class BaureiheViewModel
{
public int ID {get; set;}
public string Symbol {get; set;}
}
public class HomeController : Controller
{
SclDataEntities sclDataEntities = new SclDataEntities();
// GET: Home
public ActionResult Index()
{
ViewBag.StateList = sclDataEntities.Hersteller;
Auswahl auswahl = new Auswahl();
return View(auswahl);
}
public ActionResult FillCity(int herstellerId)
{
//check here in debug step by step
var baureihen = sclDataEntities.Baureihe.Where(c => c.HerstellerId == herstellerId);
var model = new BaureiheViewModel
{
ID = baureihen.ID,
Symbol = baureihen.Symbol
}
return Json(model, JsonRequestBehavior.AllowGet);
}
}
将breakpoit放入控制器并检查出了什么问题。据我所知(我不懂德语),您遇到了服务器端错误,请将控制器更改为:
//your viewmodel for dropdown
public class BaureiheViewModel
{
public int ID {get; set;}
public string Symbol {get; set;}
}
public class HomeController : Controller
{
SclDataEntities sclDataEntities = new SclDataEntities();
// GET: Home
public ActionResult Index()
{
ViewBag.StateList = sclDataEntities.Hersteller;
Auswahl auswahl = new Auswahl();
return View(auswahl);
}
public ActionResult FillCity(int herstellerId)
{
//check here in debug step by step
var baureihen = sclDataEntities.Baureihe.Where(c => c.HerstellerId == herstellerId);
var model = new BaureiheViewModel
{
ID = baureihen.ID,
Symbol = baureihen.Symbol
}
return Json(model, JsonRequestBehavior.AllowGet);
}
}
在控制器中放置断点并检查错误。在浏览器中按F12键,并显示下拉更改后服务器的内容。DOM Explorer/Konsole/Debugger/Netzwerk/“Reaktionsfähigkeit der Benutzeroverfläche”/Profile/Speicher/Emulation?对不起,我不是ASP.NETMVC专家!不,不,Chrome或Firefox F12,然后检查网络实际来自控制器的内容。左侧:右侧:
Serverfehler在der Anwendung/
Beim Serialiseren eines对象vom类型“System.Data.Entity.DynamicProxies.Baurehie_D6C04D64D64D44444216AA00C059E6DFD4320F713F5E08464AB657BBA396A206E63F43F”wurde ein Zirkelverweis erkannt.
和:我将@onchange
更改为onchange
在浏览器中按F12键,并显示下拉更改后从服务器提交的内容。DOM Explorer/Konsole/Debugger/Netzwerk/“Reaktionsfähigkeit der Benutzeroverfläche”/Profile/Speicher/Emulation?对不起,我不是ASP.NETMVC专家!不,不,Chrome或Firefox F12,然后检查网络实际来自控制器的内容。左侧:右侧:Serverfehler在der Anwendung/
Beim Serialiseren eines对象vom类型“System.Data.Entity.DynamicProxies.Baurehie_D6C04D64D64D44444216AA00C059E6DFD4320F713F5E08464AB657BBA396A206E63F43F”wurde ein Zirkelverweis erkannt.
和:我将@onchange
更改为onchange
返回Json(baureihen,JsonRequestBehavior.AllowGet)因为baureihen
对于Json结果来说是错误的数据类型baureihen
需要序列化吗?@MeerArtefakt yeap。看起来您试图发送复杂的实体对象,但无法序列化。如果您发送Viewmodel,它会工作吗?对不起!是的,我正在发送一个实体框架对象,发送一个像BaureiheViewModel这样的视图模型。@MeerArtefakt Bite<代码>返回Json(baureihen,JsonRequestBehavior.AllowGet)因为baureihen
对于Json结果来说是错误的数据类型baureihen
需要序列化吗?@MeerArtefakt yeap。看起来您试图发送复杂的实体对象,但无法序列化。如果您发送Viewmodel,它会工作吗?对不起!是的,我正在发送一个实体框架对象,发送一个像BaureiheViewModel这样的视图模型。@MeerArtefakt Bite!
using Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace SclWeb
{
public class HomeController : Controller
{
SclDataEntities sclDataEntities = new SclDataEntities();
// GET: Home
public ActionResult Index()
{
ViewBag.StateList = sclDataEntities.Hersteller;
Auswahl auswahl = new Auswahl();
return View(auswahl);
}
public ActionResult FillCity(int herstellerId)
{
var baureihen = sclDataEntities.Baureihe.Where(c => c.HerstellerId == herstellerId);
return Json(baureihen, JsonRequestBehavior.AllowGet);
}
}
}
//your viewmodel for dropdown
public class BaureiheViewModel
{
public int ID {get; set;}
public string Symbol {get; set;}
}
public class HomeController : Controller
{
SclDataEntities sclDataEntities = new SclDataEntities();
// GET: Home
public ActionResult Index()
{
ViewBag.StateList = sclDataEntities.Hersteller;
Auswahl auswahl = new Auswahl();
return View(auswahl);
}
public ActionResult FillCity(int herstellerId)
{
//check here in debug step by step
var baureihen = sclDataEntities.Baureihe.Where(c => c.HerstellerId == herstellerId);
var model = new BaureiheViewModel
{
ID = baureihen.ID,
Symbol = baureihen.Symbol
}
return Json(model, JsonRequestBehavior.AllowGet);
}
}