How do I get the Area (or the path) of where a View is being scaffolded?

awrigley

PROBLEM:

I am customizing the MVC 5 templates for scaffolding views.

I need to be able to get the area name for the area where the view is being created.

EG, I want to get be able to set the value for the variable areaName for the Url Action params:

Url.Action("Index", "<#= ViewDataTypeShortName#>s", new { area = "<#= areaName #>", page<#= ViewDataTypeShortName#>s = x }), ViewContext, NormalizePath("~/Areas/<#= areaName #>/Views/<#= ViewDataTypeShortName#>s/"))

In a controller, I can do:

<#   
   var areaName = GeneratedTextTransformation.AreaName;
#>

But in the View T4 template this is not available.

So how would I get the name of the area where I am creating the view?

EDIT:

Because MVC uses convention over configuration, I could get the area if I had a way to get the path of the View file that is being created (as in:

/Areas/[Area Name]/Views/

So the question reduces to:

QUESTION:

How do I get the path of where a View is being created by the T4 ASP.NET MVC scaffolding?

awrigley

I have solved this by using the AreaName property (available in T4 template for controller) in ViewBag.AreaName and reading this in the view.

NOT pretty, but it will work.

However, I would much sooner know how to access the Area the files are being created in in my T4 code. See the edit to my question.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

How do I get MVC to find my controller path?

来自分类Dev

puppet - How do I append to path variable?

来自分类Dev

How can I get the application path in C?

来自分类Dev

How do I use a relative path instead of an absolute path

来自分类Dev

How do I do a simple "Update [table] where [anyfield] = [anyvalue]

来自分类Dev

How do I find the path of a data file in Dancer to use in Javascript?

来自分类Dev

How do I proc out with tilde expansion AND $PATH searching in Haskell?

来自分类Dev

How can I get path to current twig template dynamically?

来自分类Dev

How do I use Jest to test a React view wired to store?

来自分类Dev

How do I compare two lists as being equal and containing the same objects, in Dart?

来自分类Dev

Qt Creator in Windows - How do I know which compiler is being used?

来自分类Dev

Where do I get Google Calendar API v3 .dll files (ASP.NET)?

来自分类Dev

How can I get the x/y location of a touch relative to the entire view when I touch a button?

来自分类Dev

How view the navigation path in the master page?

来自分类Dev

How view the navigation path in the master page?

来自分类Dev

How do you get the User Profile name in a Batch File without the complete path?

来自分类Dev

How do I get the nth derivative in my scheme program?

来自分类Dev

Swift: How do I get access to the navigationController in AppDelegate

来自分类Dev

How do I get my aliases to have correct completion?

来自分类Dev

How do i get MS EXCEL to Connect to MYSQL Database

来自分类Dev

How do I get Avg and Sum in Spark RDD

来自分类Dev

How do I get my nested if statement to work in jQuery

来自分类Dev

How do I get Ruby to search for a pattern on the tail of a local file?

来自分类Dev

How do I get the computer's current language in Go?

来自分类Dev

How do I get a value from an associative array using Swift

来自分类Dev

How do I efficiently crop an *indexed* Bitmap and get an *indexed* result?

来自分类Dev

How do I get `sbt test` to recognize my custom target?

来自分类Dev

How do I get the length of the first line in a multi line string?

来自分类Dev

How do I get the matching id for every record?

Related 相关文章

  1. 1

    How do I get MVC to find my controller path?

  2. 2

    puppet - How do I append to path variable?

  3. 3

    How can I get the application path in C?

  4. 4

    How do I use a relative path instead of an absolute path

  5. 5

    How do I do a simple "Update [table] where [anyfield] = [anyvalue]

  6. 6

    How do I find the path of a data file in Dancer to use in Javascript?

  7. 7

    How do I proc out with tilde expansion AND $PATH searching in Haskell?

  8. 8

    How can I get path to current twig template dynamically?

  9. 9

    How do I use Jest to test a React view wired to store?

  10. 10

    How do I compare two lists as being equal and containing the same objects, in Dart?

  11. 11

    Qt Creator in Windows - How do I know which compiler is being used?

  12. 12

    Where do I get Google Calendar API v3 .dll files (ASP.NET)?

  13. 13

    How can I get the x/y location of a touch relative to the entire view when I touch a button?

  14. 14

    How view the navigation path in the master page?

  15. 15

    How view the navigation path in the master page?

  16. 16

    How do you get the User Profile name in a Batch File without the complete path?

  17. 17

    How do I get the nth derivative in my scheme program?

  18. 18

    Swift: How do I get access to the navigationController in AppDelegate

  19. 19

    How do I get my aliases to have correct completion?

  20. 20

    How do i get MS EXCEL to Connect to MYSQL Database

  21. 21

    How do I get Avg and Sum in Spark RDD

  22. 22

    How do I get my nested if statement to work in jQuery

  23. 23

    How do I get Ruby to search for a pattern on the tail of a local file?

  24. 24

    How do I get the computer's current language in Go?

  25. 25

    How do I get a value from an associative array using Swift

  26. 26

    How do I efficiently crop an *indexed* Bitmap and get an *indexed* result?

  27. 27

    How do I get `sbt test` to recognize my custom target?

  28. 28

    How do I get the length of the first line in a multi line string?

  29. 29

    How do I get the matching id for every record?

热门标签

归档