未找到“联系人”视图或其主人,或者视图引擎没有支持搜索到的位置。搜索了以下位置: [英] The view 'Contact' or its master was not found or no view engine supports the searched locations. The following locations were searched:

查看:158
本文介绍了未找到“联系人”视图或其主人,或者视图引擎没有支持搜索到的位置。搜索了以下位置:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我正在使用链接中的教程创建音乐商店应用程序,问题在于,当我刚添加新视图时,它显示错误

Hello
I am creating a music store application using the tutorial from the link and here the problem is that when i just added a new view its shows the error

Server Error in '/' Application.
 
The view 'Contact' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Contact.aspx
~/Views/Home/Contact.ascx
~/Views/Shared/Contact.aspx
~/Views/Shared/Contact.ascx
~/Views/Home/Contact.cshtml
~/Views/Home/Contact.vbhtml
~/Views/Shared/Contact.cshtml
~/Views/Shared/Contact.vbhtml





控制器代码





Controller Code

public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
 
            return View();
        }
 
        public ActionResult About()
        {
            return View();
        }
 
        public ActionResult Contact()
        {
            ViewBag.Message = "This is our contact page";
            return View();
        }
 
Layout.cshtml
 
<quote:ul id="menu" xmlns:quote="#unknown">
                    @Html.ActionLink("Home", "Index", "Home")
                    @Html.ActionLink("About", "About", "Home")
                    @Html.ActionLink("Contact", "Contact", "Home")
                >



查看文件夹结构



views

首页

ContactUs.cshtml


View Folder Structure

views
Home
ContactUs.cshtml

推荐答案

您拥有它:联系 我们 .cshtml 。为什么你认为引擎会猜到这个?

将它重命名为 Contact.cshtml 或者返回正确的视图: return View(ContactUs); 。请参阅: http://msdn.microsoft.com/en-us/library /dd460352(v=vs.108).aspx [ ^ ]
There you have it: ContactUs.cshtml. Why do you think, that the engine will guess this?
Either rename it to Contact.cshtml or return with the proper view: return View("ContactUs");. See: http://msdn.microsoft.com/en-us/library/dd460352(v=vs.108).aspx[^]


对于此错误的其他实例,返回View(logon)对我不起作用。我发现返回RedirectToAction(View,Controller)确实解决了这个问题。
For other instances of this error, return View("logon") does not work for me. I have found out that return RedirectToAction("View", "Controller") does solve this issue.


这篇关于未找到“联系人”视图或其主人,或者视图引擎没有支持搜索到的位置。搜索了以下位置:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆