ASP.NET MVC: How to reference the MVC Area root in View script paths? -


I have an ASP.NET mvc 4 application with some sub-areas. Ideally I would like to have every field as self-contained as possible, which includes all the materials, images, etc.

Is it possible to override the behavior of "~" (tilde) characters

Alternatively, there is no other common way to reference area Root?

Resource paths within your area view script should always refer to area routes rather than application routes?

Example:

  @ * "" / / area / my niftyearia / images / logo page "should indicate: * @ @ Url.Content ("~ / images / logo.png");   

Note: The reason behind this is that I have some small applications I'm building an ASP.NET MVC web application, and I want to make sure that apps can be easily broken out and rearranged as needed, where there is a need A that the road should be separated into its own applications, without dividing all the resources / script files and clearly changing one group - the definitive path.

Of course, if this is achieved There is a better way to do this, then I am also open to it.

  ifAppRelative {string absoluteContentPath = VirtualPath Utility. Tosolute (contentpath, hpcontext requests; applicationspath); Return GenerateClientUrlInternal (httpContext, absoluteContentPath); }   

However you can definitely write your assistant and put it on the page.

What you need to do to override ViewPage with your own class on this page by specifying @ inheritance (or you can do it in Vista, see this blog for initial pointers)

Now you can create your own URL helper property and make sure that you override the inthelfer in your view page. The original code does:

  Public Virtual Zero InitHelpers () {Ajax = New AjaxHelper & lt; Object & gt; (ViewContext, this); HTML = new HtmlHelper & lt; Object & gt; (ViewContext, this); Url = new URL helper (view request). }   

Replace the URL initiator with your assistant.

My personal opinion - it sounds like a huge hammer and you'll copy many resources and possibly bug and area / region compatibility issue.

Depending on the question given below you can add a static GetAreaPath (see my observations why this framework is not piece):

  public static string GetAreaPath ( ) {Var Margadata = HTTP CONTEX. Running request. Request Number RTout data; Object areabab; If (MargaataV.ValueTragetValue ("Area", Outside Area)) {string area = areaobj as string; If (field! = Null) {return @ "~ / regions /" + area; }} Return "~"; }    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -