C# 如何使用 Razor 从我的视图中调用控制器操作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19869708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do i call a controller action from within my view using Razor?
提问by Jimmyt1988
I have 2 Controllers
我有 2 个控制器
- HomeController
- Index()
- AccountController
- Login()
In my Home/Index.cshtml I want to Load The AccountController/Login method which then returns a view and displays it in my Home/Index view.
在我的 Home/Index.cshtml 中,我想加载 AccountController/Login 方法,然后返回一个视图并将其显示在我的 Home/Index 视图中。
Home/Index.cshtml
主页/Index.cshtml
<div class="row-fluid">
<div class="col-md-12">
<!-- Render the view that the AccountController/Login method denotes -->
</div>
</div>
How do I do this?
我该怎么做呢?
采纳答案by Kamil Budziewski
use this with your actual Controller/View names
将此与您的实际控制器/视图名称一起使用
@Html.Partial("../Home/Login", model)
or
或者
@Html.Action("action", "controller", parameters)