简体   繁体   English

在MVC4中获取错误

[英]Getting error in mvc4

Error:- 错误:-

Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'. 执行处理程序'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper'的子请求时出错。

My Main page View is this 我的主页视图是这个

    {
    ViewBag.Title = "Start";
}

<h2>Start</h2>
<script type="text/javascript"> 

    $(document).ready(function () {

        $("#test1").click(function (e) {
            $("#firstpartialview").css("display", "none");
            $("#secondpatialview").css("display", "none");
            $("#firstpartialview").css("display", "block");
        });

        $("#test2").click(function (e) {
            $("#firstpartialview").css("display", "none");
            $("#secondpatialview").css("display", "none");
            $("#secondpatialview").css("display", "block");                
        });
    });
</script>
<a id="test1"></a>
<a id="test2"></a>
<div id="firstpartialview">@Html.Action("FirstView", "Home")   </div>
<div id="secondpatialview">@Html.Action("SecondView", "Home")   </div>

My controller is this:- 我的控制器是这样的:

public ActionResult Start()
{
    return View();
}

public ActionResult FirstView()
{
    ModelA objA = new ModelA();
    return PartialView(objA);
}

public ActionResult SecondView()
{
    ModelB objB = new ModelB();
    return PartialView(objB);
}

My Partial View is this 我的局部视图是这个

_partialA.cshtml
@model demo3.Models.ModelA

@{
    ViewBag.Title = "_partialA";
}

<h2>_partialA</h2>
<div>@Html.EditorFor(m => m.EmployeeId)  </div>
<div>@Html.EditorFor(m => m.EmployeeName) 

and another partial view is this 而另一个局部视图是

_partialB.cs.html
@model demo3.Models.ModelB

@{
    ViewBag.Title = "_partialB";
}

<h2>_partialB</h2>
<div>@Html.EditorFor(m => m.Comapny)  </div>
<div>@Html.EditorFor(m => m.FisacalYear)  </div>

Please help me to solve the error..on browser this error is coming 请帮助我解决错误..在浏览器上,此错误即将到来

The partial view 'FirstView' was not found or no view engine supports the searched locations. 找不到部分视图“ FirstView”,或者没有视图引擎支持搜索到的位置。 The following locations were searched: 搜索了以下位置:
~/Views/Home/FirstView.aspx 〜/ Views / Home / FirstView.aspx
~/Views/Home/FirstView.ascx 〜/ Views / Home / FirstView.ascx
~/Views/Shared/FirstView.aspx 〜/ Views / Shared / FirstView.aspx
~/Views/Shared/FirstView.ascx 〜/ Views / Shared / FirstView.ascx
~/Views/Home/FirstView.cshtml 〜/ Views / Home / FirstView.cshtml
~/Views/Home/FirstView.vbhtml 〜/ Views / Home / FirstView.vbhtml
~/Views/Shared/FirstView.cshtml 〜/ Views / Shared / FirstView.cshtml
~/Views/Shared/FirstView.vbhtml 〜/ Views / Shared / FirstView.vbhtml

The error is quite specific. 该错误是非常具体的。 This line is causing your error: 此行导致您的错误:

<div id="firstpartialview">@Html.Action("FirstView", "Home")   </div>

It can't find the view FirstView . 它找不到视图FirstView You need to place the view in one of the locations that the error message tells you or change where the view engine searches for your views. 您需要将视图放置在错误消息告诉您的位置之一, 更改视图引擎搜索视图的位置。

The error means that mvc is trying to load a file (by default, if you haven't specified the view file name, it checks by Action name which in this case, is FirstView), but it can't find it. 该错误表示mvc正在尝试加载文件(默认情况下,如果您未指定视图文件名,它将按Action名称(在这种情况下为FirstView)进行检查),但找不到它。

You can specify the view file name in your return statement: 您可以在return语句中指定视图文件名:

return PartialView(string "View", object model)

This can be used like so (assuming _partialA is your view's cshtml filename): 可以这样使用(假设_partialA是视图的cshtml文件名):

return PartialView("_partialA", objA);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM