我需要的是Make_Name和Model_ID在下拉列表和级联下拉列表中选择后进入链接,当您点击链接时,它会转到显示所有这些车辆的页面
使用的表: Vehicle_Make有Make_ID和Make_Name和 Vehicle_Model具有Model_ID和Model_Name
http://www.link.co.za/showroom/showroom.aspx?
s_MakeStr=BMW&s_RangeStr=&s_ModelStr=12&s_Province=0&s_MaxValue=0
因此,使用上面的链接作为示例,当我单击Make_Name时,我需要来自DropDown的“s_MakeStr”,然后来自Vehicle_Model表的“s_ModelStr”(使用Model_ID作为PK)来单击Model_Name时从Cascade下拉。 “BMW”是Make_Name,“12”是上面示例链接中的Model_ID。
每当我在两个下拉列表中进行更改时,可点击的链接应更改为新值。
控制器代码:
public ActionResult Index()
{
GoogleMapEntities GE = new GoogleMapEntities();
List<Vehicle_Details> vehList = db.Vehicle_Details.ToList();
GoogleMapViewModel GMviewmodel = new GoogleMapViewModel();
List<GoogleMapViewModel> GMviewmodelList = new
List<GoogleMapViewModel>();
//Populate the ViewModel
MyPageViewModel vm = new Models.MyPageViewModel();
vm.GoogleMapViewModelList = GMviewmodelList;
vm.SelectedMake_Id = SelectedMake_Id;
ViewBag.Vehicle_Make = new SelectList(db.GetVMSorted(), "Make_ID",
"Make_Name");
return View(vm);
}
public JsonResult GetModById(int MID)
{
db.Configuration.ProxyCreationEnabled = false;
return Json(db.DropDL().Where(p => p.Make_ID == MID)
.Select(p => new SelectListItem {Text = p.Model_Name + " " +
"- ("+p.Year + ")", Value = p.Model_ID.ToString()}).ToList(),
JsonRequestBehavior.AllowGet);
}
Index.cshtml代码:
@Html.DropDownListFor(p => p.SelectedMake_Id, ViewBag.Vehicle_Make as
SelectList, "Select Vehicle Make", new { id = "ContID", @class = "form-
control", })
@Html.CascadingDropDownListFor(
expression: m => m.SelectedModelId,
triggeredByPropertyWithId: "ContID", //Parent property that trigers
dropdown data loading
url: Url.Action("GetModById", "Map"), //Url of action that returns dropdown
data
ajaxActionParamName: "MID", //Parameter name for the selected parent value
that url action receives
optionLabel: "Please select a Model", // Option label
disabledWhenParentNotSelected: true, //If true, disables dropdown until
parent dropdown is selected
htmlAttributes: new { @class = "form-control", id = "DDMDL" })
编辑:
我添加了一个按钮代码:
var button = document.getElementById("btnSearch");
button.onclick = function () {
var text = document.getElementById("ContID").value;
var text2 = document.getElementById("DDMDL").value;
window.open("http://www.link.co.za/showroom/showroom.aspx?
s_MakeStr=" + text + "&s_RangeStr=&s_ModelStr=" + text2 +
"&s_Province=0&s_MaxValue=0");
}
还有表单代码:
<form>
<div class="form-group">
<label for="exampleInputEmail1">View Selected Model Range on Our
Site</label>
<input type="text" class="form-control" id="search">
</div>
<button type="submit" class="btn btn-default"
id="btnSearch">Submit</button>
</form>
链接确实有效,但它获取了text和text2的ID值。我需要字符串,Make_Name和Model_Name,是否可以在不更改下拉代码的情况下执行此操作?
请忽略我想要搜索Model_ID的原始问题,以及我需要Model_Name而不是ID。