当我导航到查询区域时,我的应用程序正在返回这个,我目前必须到工作区域、宣传册和查询以及第三个要遵循(支付),当我导航到宣传册区域时,不会显示错误。
我尝试在抛出错误的视图中添加一个区域参数,将字符串留空并使用查询,如下所示:
@Html.Action("DropDownList", "Enquiry Base", new { type = "titles", areas = ""})
@Html.Action("DropDownList", "Enquiry Base", new { type = "titles", areas = "Enquiry"})
这些都没有解决错误。
目前为了显示下拉列表,我在根目录中有一个视图模型、部分视图和统一引导程序:
项目视图模型
public class DropDownListItem
{
public string Text { get; set; }
public string Value { get; set; }
}
public class ItemsViewModel
{
private readonly List<DropDownListItem> _items;
public string SelectedItem { get; set; }
public IEnumerable<SelectListItem> Items
{
get
{
var allItems = _items.Select(i => new SelectListItem
{
Value = i.Value,
Text = i.Text
});
return DefaultItem.Concat(allItems);
}
}
public IEnumerable<SelectListItem> DefaultItem
{
get
{
return Enumerable.Repeat(new SelectListItem
{
Value = "",
Text = Mui.please_select
}, count: 1);
}
}
public ItemsViewModel()
{
}
public ItemsViewModel(List<DropDownListItem> items, string selected)
{
_items = items;
SelectedItem = selected;
}
下拉部分
@using MBS.Exec.Mvc.ViewModels
@model ItemsViewModel
@Html.DropDownListFor(m => m.SelectedItem, Model.Items)
引导程序
public static class Bootstrapper
{
public static void Initialise()
{
var container = BuildUnityContainer();
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
}
private static IUnityContainer BuildUnityContainer()
{
var container = new UnityContainer();
container.RegisterType<IBrochureModel, MilitaryBrochureViewModel>();
container.RegisterType<IBrochureModel, GeneralBrochureViewModel>();
container.RegisterType<IBrochureModel, StandardBrochureViewModel>();
container.RegisterType<IBrochureModel, StudentBrochureViewModel>();
container.RegisterType<IEnquiryModel, MilitaryEnquiryViewModel>();
container.RegisterType<IEnquiryModel, GeneralEnquiryViewModel>();
container.RegisterType<IEnquiryModel, StandardEnquiryViewModel>();
container.RegisterType<IEnquiryModel, StudentEnquiryViewModel>();
container.RegisterType<IFormData, FormData>();
container.RegisterType<IRESTExecutiveService, RESTExecutiveService>();
return container;
}
为了使用该区域的下拉菜单,我在 EnquiryBaseController 中创建了 DropDownList ActionResult:
[ChildActionOnly]
public ActionResult DropDownList(string type, string selected)
{
if (type == "titles")
{
var items = new ItemsViewModel(
(from g in _service.GetTitles() select new DropDownListItem { Text = g.Value, Value = g.Value }).ToList(),
selected);
return PartialView("DropDownPartial", items);
}
else if (type == "leadSources")
{
var items = new ItemsViewModel(
(from g in _service.GetLeadSources() select new DropDownListItem { Text = g.Value, Value = g.Value }).ToList(),
selected);
return PartialView("DropDownPartial", items);
}
return null;
}
然后我使用上面的@Html.Action 代码在视图上呈现下拉菜单。
有谁知道为什么会抛出这个错误?