我在局部视图中正在做Html.BeginForm
。在主视图中,我使用角度ng-repeat
来显示图像集。然后显示部分视图中的表单。
我的观点:
<div class="tab-content">
<div id="home" class="tab-pane fade in active">
<div id="accordion">
<h3>Search by Manufacturer</h3>
<div class="manufacturerDiv">
<ul class="manufacturerList">
<li ng-repeat="item in manufacturerList"><a href="/Deal/{{item.ManufacturerName}}"><img src="/Content/ModelImages/{{item.Logo}}" height="20" width="20" alt="{{item.ManufacturerName}}" /></a></li>
</ul>
</div>
<h3>Search by Price</h3>
@{Html.RenderAction("SearchByPrice", "Deal");}
</div>
</div>
</div>
我的部分观点:
@model VC.Website.Models.SearchDealbyPriceVM
@using (Html.BeginForm("SearchByPrice", "Deal", FormMethod.Post)) {
<form id="enq_form">
<div class="form-group">
<div class="col-lg-4">
@Html.DropDownListFor(x => x.CategoriesID, new SelectList(Model.Categories, "Key", "Value"), "Select Category", new { @class = "form-control categorydropdown" })
</div>
<div class="col-lg-4">
@Html.TextBoxFor(x => x.FromPrice, new { @placeholder = "From Price £", @class = "form-control" })
</div>
<div class="col-lg-4">
@Html.TextBoxFor(x => x.ToPrice, new { @placeholder = "To Price £", @class = "form-control" })
</div>
<i class="clear_0"></i>
</div>
<div class="form-group">
<div class="col-lg-12">
@Html.RadioButtonFor(x => x.IsBusinessPrice, "true", new { @class = "form-control" })
<label class="radiolabel">Business</label>
@Html.RadioButtonFor(x => x.IsBusinessPrice, "false", new { @class = "form-control" })
<label class="radiolabel">Personal</label>
@Html.CheckBoxFor(x => x.GreenCars, new { @class = "form-control" })
<label class="radiolabel">@Html.DisplayNameFor(x => x.GreenCars)</label>
</div>
<i class="clear_0"></i>
</div>
<div class="form-group">
<div class="col-lg-12 enquire_btn_wrap">
<button type="submit" class="btn btn-default en_btn">Enquire About this Car</button>
</div>
<i class="clear_0"></i>
</div>
</form>
}
控制器:
[System.Web.Mvc.HttpPost]
public ActionResult SearchByPrice(SearchDealbyPriceVM model)
{
return RedirectToAction("Index", new { CategoriesID = model.CategoriesID, FromPrice = model.FromPrice, ToPrice = model.ToPrice, Price=model.IsBusinessPrice, GreenCars = model.GreenCars,PageName="SpecialGarage" });
}
Route.config:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Error", "Home/Error");
routes.MapRoute("Deal", "Deal", defaults: new { controller = "Deal", action = "Index" });
routes.MapRoute("DealManufacturer", "Deal/{ManufacturerName}", defaults: new { controller = "Deal", action = "Index", id = UrlParameter.Optional });
routes.MapRoute("Home", "Home", defaults: new { controller = "Home", action = "Index" });
routes.MapRoute("SpecialGarage", "SpecialsGarrage", defaults: new { controller = "Deal", action = "SpecialsGarrage" });
routes.MapRoute("TotalCare", "TotalCare", defaults: new { controller = "Deal", action = "TotalCare" });
routes.MapRoute("GreanDeal", "GreanDeal", defaults: new { controller = "Deal", action = "GreanDeal" });
routes.MapRoute("AboutUs", "AboutUs", defaults: new { controller = "Page", action = "Index" });
routes.MapRoute("UsefulLinks", "UsefulLinks", defaults: new { controller = "Page", action = "Index" });
routes.MapRoute("Contact", "Contact", defaults: new { controller = "Contact", action = "Index" });
routes.MapRoute("WholeLifeCosts", "WholeLifeCosts", defaults: new { controller = "Page", action = "Index" });
routes.MapRoute("Proposals", "Proposals", defaults: new { controller = "Contact", action = "Proposals" });
routes.MapRoute("QuickContact", "QuickContact", defaults: new { controller = "Contact", action = "QuickContact" });
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
当我提交表单时,它会将错误返回为
匹配的路线不包含&#39;控制器&#39;路线值,这是必需的。
我在这段代码中做错了什么?
答案 0 :(得分:0)
您未指定此路线的默认控制器和操作
class MyExtraFields extends DataObject {
private static $db = array(
'ExtraText' => 'Varchar(255)',
'ExtraWYSIWYG' => 'HTMLText'
);
private static $has_many = array(
'Article' => 'Article'
);
private static $summary_fields = array(
'ExtraText' => 'ExtraText',
'ExtraWYSIWYG' => 'ExtraWYSIWYG'
);
public function updateCMSFields(){
$fields = parent::getCMSFields();
$fields->addFieldsToTab('Root.Content.Translation', array(
TextField::create('ExtraText'),
HTMLEditorField::create('ExtraWYSIWYG')
)
);
return $fields;
}
}
您应指定默认控制器和操作
routes.MapRoute("Error", "Home/Error");
或者,如果您希望routes.MapRoute(
name: "Error",
url: "Home/Error",
defaults: new { controller = "YourControllerName", action = "YourActionName" }
);
网址在Home/Error
控制器中调用Error
操作,则可以删除上述路由,因为Home
网址将被默认路由覆盖< / p>
Home/Error