2
In ASP.NET MVC it is possible to run the @Url.Content
views and controllers.
This variable returns the relative level at which the site is.
My question is: how to execute the Url.Content
via Javascript? There is some form in MVC?
EDITED
Example of @Url.Content
in the C#
<img src="@Url.Content("~/Content/img/teste.jpg")" />
Result per environment
| DEV | /Content/img/teste.jpg" | | PRD | /NovoSite/Content/img/teste.jpg" |
In my case, the production environment is inside a "Novosite" folder, using the @Url.Content
I don’t have to worry about this.
But if I’m going to do something with javascript/jquery example
$("#element").html('<img src="/Content/img/teste.jpg" />');
It will only work in my Dev environment, and I need to change the path every time I deploy
Tiago, could you add an excerpt of code showing what you want to do? I think I get it, but I want to make sure.
– Andre Calil
Just to clarify: You want to know this because you will need to use this path in some other function
javascript
, right? You can tell us more about this?– Vitor Canova
@Andrecalil put the example code but in chsarp
– Tiago
@Vitorcanova this same, I added more details in the post, thanks
– Tiago