调用来自控制器使用ASP.NET MVC 4另一个不同的看法 [英] Calling another different view from the controller using ASP.NET MVC 4

查看:107
本文介绍了调用来自控制器使用ASP.NET MVC 4另一个不同的看法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个提交按钮的视图(Index.cshtml)。当点击提交按钮,它会调用控制器(TestController.cs)内的动作(Action01),所以在我要返回给调用者(Index.cshtml)视图中,带有自定义视图模型参数的动作结束。我该怎么做呢?

I have a view (Index.cshtml) with a submit button. When the submit button is clicked, it calls an action (Action01) within the controller (TestController.cs) so at the end of the action I want to return to the caller (Index.cshtml) view with a custom view model as a parameter. How do I do this?

在结果第一次尝试使用视图(视图名,模型):

Results after first attempt using View("ViewName",model):

这是引发错误,因为动作控制器的测试中,所以返回时,它搜索\\查看\\测试\\指数,和我的索引页是\\查看\\首页\\目录。

An error is raised, as the action is within the controller Test, so returning, it is searching for \Views\Tests\Index, and my Index page is in \Views\Home\Index.

视图索引或它的主人没有被发现或没有视图引擎支持搜索位置。在以下地点进行了全面搜查:

The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:

~/Views/Test/Index.aspx
~/Views/Test/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Test/Index.cshtml
~/Views/Test/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml

最终的解决方案:

我用返回视图(视图名,模型),我已经改变了我的目录结构,因为它是这个问题。

Final solution:

I have used return View("ViewName", model), and I have changed my directories structure as it was the problem.

推荐答案

您可以直接返回像一个不同的看法:

You can directly return a different view like:

return View("NameOfView", Model);

或者你可以做一个局部视图,并且可以返回,如:

Or you can make a partial view and can return like:

return PartialView("PartialViewName", Model);

这篇关于调用来自控制器使用ASP.NET MVC 4另一个不同的看法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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