Html.Action或Html.Partial无法与属性路由一起使用

时间:2019-09-04 19:31:32

标签: c# asp.net .net asp.net-mvc asp.net-mvc-5

我有一个定义为

的简单测试控制器
[Route("~/testAction/testcontroller/{viewhash}")]
public ActionResult ATest(string viewHash)
        {
            var viewname = commonDataCollection.Instance.WidgetHashList[viewHash];
            return Content($"Success hash by view name is: {viewhash}","text/html");
        }

如果我从浏览器http://localhost:49359/testAction/testcontroller/FuMmWA1217dgnaT调用它,这将起作用

如果我使用实际的动作/控制器名称而不是属性路由值,但如果我尝试对Html Helper执行相同的操作,并且定义了诸如以下的路由,则下面的方法有效:

@Html.Action("testAction", new { viewhash = "FuMmWA1217dgnaT",area="",controller= "testcontroller" });

@Html.Partial("testAction", new { viewhash = "FuMmWA1217dgnaT",area="",controller= "testcontroller" });

或者甚至当我尝试渲染功能时,我也会遇到以下错误:

  

子请求的执行失败。请检查   有关更多信息,请参见InnerException。在   System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap [TResult](Func 1 func) at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerAsyncWrapper.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) at System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) at System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) at System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) at System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, Object routeValues) at ASP._Page_Views_widgetrenders_contact_cshtml.Execute() in D:\Projects\company projects\CMSAlpha\CMSAlpha\Views\widgetrenders\contact.cshtml:line 20 The controller for path '/2/abc' was not found or does not implement IController. System.Web.HttpException (0x80004005): The controller for path '/2/abc' was not found or does not implement IController. at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerAsyncWrapper.<>c__DisplayClass7.<BeginProcessRequest>b__6() at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap[TResult](Func 1   func)在   System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext   requestContext,类型为controllerType),位于   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext   requestContext,字符串controllerName)   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase   httpContext,IController&控制器,IControllerFactory&工厂),网址为   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase   httpContext,AsyncCallback回调,对象状态)位于   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext,   AsyncCallback回调,对象状态)位于   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext   上下文,AsyncCallback cb,对象extraData)位于   System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerAsyncWrapper。<> c__DisplayClass7.b__6()   在   System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap [TResult](Func`1   功能)

0 个答案:

没有答案
相关问题