Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Defining Path in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 295
    Comment on it

    Hi All,
    This blog is simply to know the fact that in MVC4 we no longer need to use "Url.Content".

    The Content method is a helper method which is responsible for converting a relative path into an absolute path. But with MVC4 release, we can simplify our code so that it looks like this:

    <script src="~/scripts/myscript.js"></script>

    Yes, we no longer need to resort to the helper because Razor is smart enough to translate all attribute’s values that start with ~/ into a   @Url.Content call. For instance, if the parser finds this:

    <div data-info="~/info.txt">Some info</div>

    It’s as if you had written this:

    <div data-info="@Url.Content("~/info.txt")">Some info</div>

    Notice you can also mix values with other code snippets. For instance, suppose you need to build an URL that combines an URL with some variable sample. In that case, you can simply write something like this:

    <script src="~/scripts/@sample"></script>

    The previous snippet will get translated into the following:

    <script src="@Url.Content("~/scripts/")@sample"></script>

    Make your code simple....

    Happy Coding

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: