MVC3 的奇怪行为
我创建了一个自定义模型 ie 来支持我的 Razor 视图。然后我创建了一个控制器,如下所示的命名空间 MyCandidate.Controllers
public class CandidateViewModelController : Controller
{
//
// GET: /CandidateViewModel/
public ActionResult Index()
{
return View();
}
}
我在 _Layout.cshtml 中也有以下语句
@Html.ActionLink("Canid", "Index", "CandidateViewModel")
接下来我创建了一个视图,该视图的第一个语句是
@model MyCandidate.Models.CandidateViewModel
当我运行我的项目时,我收到以下错误
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
我花费了更多超过3小时但无法弄清楚?
I created a custom Model i.e. to support my Razor View. Then I created a controller as following`namespace MyCandidate.Controllers
public class CandidateViewModelController : Controller
{
//
// GET: /CandidateViewModel/
public ActionResult Index()
{
return View();
}
}
I also have the following statement in my _Layout.cshtml
@Html.ActionLink("Canid", "Index", "CandidateViewModel")
Next i created a view and the very first statement of the view is
@model MyCandidate.Models.CandidateViewModel
when i run my project i get the following error
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
I spent more than 3 hours but could not figure out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
Index()
未获取任何参数,但您发送"CandidateViewModel")
添加带有属性Index(string input)
方法 < code>[HttpGet] 到控制器。此错误表示您尚未在“Views/CandidateViewModel/Index.cshtml”中查看“Index”。
也许您删除了母版页文件(_ViewSrat,_Layout)
或者您在更改路线时犯了错误
your
Index()
not get any parameters, but you send"CandidateViewModel")
addIndex(string input)
method with attribute[HttpGet]
to controller.this error meen you haven't view "Index" in "Views/CandidateViewModel/Index.cshtml".
Maybe you delete master page files (_ViewSrat, _Layout)
Or you made a mistake when you change your routes
将 ActionLink 更改为:
如果您想将任何数据传递给 View ,您还可以使用 ViewBag:
Change your ActionLink to:
If you want to pass any data to View , you can also use ViewBag: