简体   繁体   English

如何将View返回到.net核心Web应用程序中的另一个项目(模块)

[英]How to return View into another project (modules) in .net core web application

I am setting up an architecture like modular programming, But I would like to return the view from one project to another project. 我正在建立一种类似于模块化编程的体系结构,但是我想将视图从一个项目返回到另一个项目。

I had tried with the codes which i have found from, 我尝试使用从中找到的代码,

  1. https://www.codeproject.com/Articles/1109475/Modular-Web-Application-with-ASP-NET-Core https://www.codeproject.com/Articles/1109475/Modular-Web-Application-with-ASP-NET-Core
  2. http://www.binaryintellect.net/articles/90d7323f-dcde-40d4-aa30-987bc8db1bf4.aspx http://www.binaryintellect.net/articles/90d7323f-dcde-40d4-aa30-987bc8db1bf4.aspx

Project structure may like, 项目结构可能像

WebApplicaitonModule1
        Controllers
        Views
        Layouts

WebApplicationModule2
        Controllers
        Views
        Layouts

WebApplicationModule3
        Controllers
        Views
        Layouts

WebApplicationModule4
        Controllers
        Views
        Layouts

Models and DAL are different libraries

I need something like, how to redirect/return the View from Module1 to the view of Module2's Page?. 我需要类似的东西,如何将视图从Module1重定向/返回到Module2页面的视图? is that possible in .net core applications. .net核心应用程序有可能做到这一点。 I am using .net core 2.1. 我正在使用.net core 2.1。

Because the I need to get the layout differently in Module wise. 因为我需要在Module明智地获得不同的布局。

My Imaginary scenario,
 - In WebApplicationModule2 we have a action like this and it will return the view.
public IActionResult Index()
        {
            model objmodel = new model();
            return View("~/Home/Index.cshtml",objmodel );
        }

 then after adding Project Dependency, 
 - from WebApplicationModule1

public IActionResult Index()
        {
            model objmodel = new model(); // same model return from another project.
            return View("~/WebApplicationModule2/Home/Index.cshtml",objmodel );
        }

How can we achieve this? 我们怎样才能做到这一点? or is there any other ways to do this? 还是有其他方法可以做到这一点? Any help is appreciate. 任何帮助表示赞赏。

I think you can use redirect to route like this. 我认为您可以使用重定向来进行这样的路由。 I'm not know about your controller name so you need to pass in controller you want to redirect to and the model you want to pass in that controller method 我不知道您的控制器名称,因此您需要传入要重定向到的控制器,以及传入该控制器方法的模型

return RedirectToRoute(new 
{ 
    controller = "", 
    action = "Index", 
    model = model
});

Please let me know if you need any help. 如果您需要任何帮助,请告诉我。 Cheers 干杯

Add the child projects as Razor Class Library. 将子项目添加为Razor类库。

Add as Project reference( This will include all the reference files which used in the Razor class library project) or as an assembly reference( which contains only the .dll and view.dll) 添加为项目参考(将包括Razor类库项目中使用的所有参考文件)或作为程序集参考(仅包含.dll和view.dll)

and then it will be easily we can call the views( better if we added as Area wise), 然后我们可以很容易地调用视图(最好将其添加为Area明智),

In WebApplicationModule2 we have an action like this and it will return the view.

public IActionResult Index()
    {
        model objmodel = new model();
        return View("~/Home/Index.cshtml",objmodel );
    }

Add as project reference or assmebly reference then from WebApplicationModule1. 然后从WebApplicationModule1中添加为项目参考或组装参考。

public IActionResult Index()
    {
        model objmodel = new model(); // same model return from another project.
        return View("~/WebApplicationModule2/Home/Index.cshtml",objmodel );
    }

the passing model should be the same. 传递的模型应该相同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 ASP.NET Core 中的另一个项目返回视图? - How to return view from another project in ASP NET Core? How to add .net core Web API project to an existing .NET core (3.1) Web Application project? - How to add .net core Web API project to an existing .NET core (3.1) Web Application project? 如何使用 post 将数据传递到另一个 .Net Core Web 应用程序 - How to pass data to another .Net Core web application using post 成功登录并重定向到另一个剃须刀视图 ASP.NET Core MVC Web 应用程序后,UserIdentity 为 null - UserIdentity is null after successful login and redirection to another razor view, ASP.NET Core MVC web application 如何在.net核心项目中添加View路由? - How to add View routing in a .net core project? Visual Studio 2017 中的空 ASP .NET Core Web 应用程序项目 - Empty ASP .NET Core Web Application project in Visual studio 2017 从另一个项目初始化ASP.NET Core Web API - Initialize ASP.NET Core Web API from another project 如何使asp.net核心应用程序在当前项目中查找视图文件? - How to make asp.net core application to look for view files in the current project? 如何将位于应用程序部分 (DLL) 中的部分视图呈现到主 asp.net 核心 2.2 项目中 - How to render a partial view located in an application part (DLL) into main asp.net core 2.2 project 使用Kestrel在.NET Core控制台应用程序中返回HTML视图 - Return HTML view in .NET Core Console application with Kestrel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM