MVC3 的奇怪行为

发布于 2024-12-10 19:23:40 字数 709 浏览 0 评论 0原文

我创建了一个自定义模型 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦太阳 2024-12-17 19:23:40
  1. 您的 Index() 未获取任何参数,但您发送 "CandidateViewModel") 添加带有属性 Index(string input) 方法 < code>[HttpGet] 到控制器。

  2. 此错误表示您尚未在“Views/CandidateViewModel/Index.cshtml”中查看“Index”。

  3. 也许您删除了母版页文件(_ViewSrat,_Layout)

  4. 或者您在更改路线时犯了错误

  1. your Index() not get any parameters, but you send "CandidateViewModel") add Index(string input) method with attribute [HttpGet] to controller.

  2. this error meen you haven't view "Index" in "Views/CandidateViewModel/Index.cshtml".

  3. Maybe you delete master page files (_ViewSrat, _Layout)

  4. Or you made a mistake when you change your routes

桃扇骨 2024-12-17 19:23:40

将 ActionLink 更改为:

@Html.ActionLink("Canid", "Index")

如果您想将任何数据传递给 View ,您还可以使用 ViewBag:

// Controller :
ViewBag.CandidateValues = CandidateViewModelData;

// View 
@Html.Label("LabelName", (CandidateViewModel) ViewBag.CandidateValues.FiledName);

Change your ActionLink to:

@Html.ActionLink("Canid", "Index")

If you want to pass any data to View , you can also use ViewBag:

// Controller :
ViewBag.CandidateValues = CandidateViewModelData;

// View 
@Html.Label("LabelName", (CandidateViewModel) ViewBag.CandidateValues.FiledName);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文