我是网络语言的新手。我在我的 Visual Studio 2010 上启动了一个 .NET 项目,它采用 MVC 4 和 razor 结构。
问题是我在views文件夹中有一个文件夹,里面有一个视图,但是当我尝试访问视图时出现这个错误:
The view 'searchWeb' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/searchWeb.aspx
~/Views/Home/searchWeb.ascx
~/Views/Shared/searchWeb.aspx
~/Views/Shared/searchWeb.ascx
~/Views/Home/searchWeb.cshtml
~/Views/Home/searchWeb.vbhtml
~/Views/Shared/searchWeb.cshtml
~/Views/Shared/searchWeb.vbhtml
我猜他没有在正确的文件夹中搜索...但是如何更改呢?我看了一些主题,显然我必须制作一个新的 viewEngine 并继承旧的?是否可以在不制作新视图引擎的情况下修复它?或者你能告诉我如何制作新的视图引擎吗?谢谢你 !
编辑:
这是我的 homeController.cs:
namespace Searcher.Controllers
{
public class HomeController : Controller
{
public ActionResult homeWeb()
{
ViewBag.Message = "Searching for sites over the web.";
return View();
}
public ActionResult homeImages()
{
ViewBag.Message = "Searching for images over the web.";
return View();
}
public ActionResult homeVideos()
{
ViewBag.Message = "Searching for videos over the web.";
return View();
}
[HttpPost]
public ActionResult searchWeb()
{
// do something with the search value
return View();
}
}
}
这是我的 homeWeb,它正在调用 searchWeb:
@{
ViewBag.Title = "Search Web";
}
@section featured {
<section class="featured">
<div class="content-wrapper">
<hgroup class="title">
<h1>@ViewBag.Title.</h1>
<h2>@ViewBag.Message</h2>
</hgroup>
</div>
</section>
}
@using (Html.BeginForm("searchWeb", "Home", FormMethod.Post, new { id = "searchForm" }))
{
<div class="main-block">
<p>
<div>
<input size="200px" type="text" name="searchValue" />
</div>
<div>
<input type="submit" value="Submit" />
</div>
</p>
</div>
}