正确的术语和ASP.NET MVC中嵌套/路由视图的示例 [英] Correct terminology and examples for nesting/routing views in ASP.NET MVC

查看:58
本文介绍了正确的术语和ASP.NET MVC中嵌套/路由视图的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做ASP.NET了一段时间,并在MVC已经做得很少(一般),但很新的ASP.NET MVC框架,以及对一些事情的正确的术语。

下面是我的例子(我工作的实际应用是不同的,但是这是一个公开的例子我可以使用) - 我想创建的管理平台,但在.NET。

我想列出的问题,以这样的方式,如果我去example.org/issues,我看到的所有问题清单(类似的 http://www.redmine.org/issues ),在所有项目。

但是,如果我去的项目,如example.org/project/issues,我看到的只是该项目的问题(类似的 http://www.redmine.org/projects/redmine/issues )。这将是example.org/project2/issues同一等

什么是这个正确的称呼?我会认为开发商没有改写'问题'code在两个地方,他们再利用这code。

由于我不知道这样做的完全正确的术语,它是很难找到在ASP.NET MVC世界很好的例子,我可以开始。所以这第二部分,是将是一个例子,我可以看看ASP.NET MVC,以及如何把这个看在Visual Studio中吗?

有也将是下/项目/其他几个东西,比如设置,细节,日志等,在一个将如何定位相似的 http://www.redmine.org/projects/redmine/

最后,如果项目并不在顶层?如,如果我的应用程序是什么更像是:

  example.org/
example.org/projects/
example.org/projects/project1
example.org/projects/project1/issues
example.org/projects/project2
example.org/dashboard/


解决方案

设置称为一个控制器无论你想(我将使用RedMineController)。

在该控制器你就会有一个动作方法命名ListIssues。接受一个参数命名的项目名:

 公众的ActionResult ListIssues(字符串项目名){}

最后在你的global.asax.cs创建两个路线:

  routes.MapRoute(
    问题根源
    问题
    新{控制器=管理平台,行动=ListIssues}
);routes.MapRoute(
    工程问题,
    项目/ {} PROJECTNAME /问题
    新{控制器=管理平台,行动=ListIssues}
);

在您ListIssues行动,检查项目名== NULL,如果是这样获得的所有问题,否则得到具体的。第一条路线将经过空,第二次将传递什么是在URL。不要忘了扔404,如果在URL中的项目名称是无效的。

希望这有助于!

I have been doing ASP.NET for a while, and have done very little in MVC (in general), but very new at the ASP.NET MVC framework, as well as the correct terminology on a few things.

Here is my example (actual application I am working on is different, but this is a public example I can use) - I want to create a simpler version of Redmine, but in .net.

I want to list issues, in such a way that if I go to example.org/issues, I see a list of all issues (similar to http://www.redmine.org/issues), across all projects.

But if I go to the project, as in example.org/project/issues, I see just the issues for that project (similar to http://www.redmine.org/projects/redmine/issues). This would be the same for example.org/project2/issues, etc.

What is the correct term for this? I would assume that the developers didn't rewrite the 'issues' code in two places, that they reused this code.

Since I don't know the fully correct term for this, it is hard to find good examples in the ASP.NET MVC world that I can start with. So the second part of this, is what would be an example that I could look at in ASP.NET MVC, and how should this look in Visual Studio to me?

There would also be several other things under /project/, like settings, details, logs, etc, similar on how one would navigate http://www.redmine.org/projects/redmine/.

Finally, what if projects was not on the top level? As in, what if my application was more like:

example.org/
example.org/projects/
example.org/projects/project1
example.org/projects/project1/issues
example.org/projects/project2
example.org/dashboard/

解决方案

Set up one controller called whatever you'd like (I'll use RedMineController).

In that controller you'll have a single action method named ListIssues. Accept a parameter named ProjectName:

public ActionResult ListIssues(string projectName) {}

Lastly create two routes in your global.asax.cs:

routes.MapRoute(
    "Issues Root",
    "issues",
    new { controller = "RedMine", action = "ListIssues" }
);

routes.MapRoute(
    "Project Issues",
    "projects/{projectName}/issues",
    new { controller = "RedMine", action = "ListIssues" }
);

In your ListIssues action, check if projectName == null, and if so get all issues, otherwise get specific ones. The first route will pass null, the second will pass what is in the URL. Don't forget to throw a 404 if the project name in the URL is invalid.

Hope this helps!

这篇关于正确的术语和ASP.NET MVC中嵌套/路由视图的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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