You must Sign In to post a response.
  • Category: ASP.Net MVC

    CSHTML code display in view source


    I have one simple application in mvc 5.
    Here, I have written simple logic to display user name and other details of the logged in user.
    For this, I have assigned some values to session and the code is written in cshtml using JSON.

    Code is like,
    sessionStorage.VirtualRoleId = '173';
    sessionStorage.UserName= 'RAN';
    sessionStorage.Branch= 'India';

    If i open this page in browser and check view source, i can see this logic which I dont want to display.
    Is there any other way to do this so that, my logic will not display in browser.
  • #764971
    We can not hide this in the view source.
    1. You can handle the logic in the code controller.
    2. You can try to restrict the user to do the right click
    Following are sample javascripts

    document.addEventListener("contextmenu", function(e){
    }, false);

    By Nathan
    Direction is important than speed

  • #765639
    You can bind a view model to this view and assign these values to viewmodel.

Sign In to post your comments