locked
Cshtml pages not rendered properly RRS feed

  • Question

  • User-1272177930 posted

    After, I published to target host server my default page rendered correctly but two other pages did not render correctly all my code behind were displayed with some other simple html objects. See a screen shot below:

    @{     WebImage photo = null ;      var newFileName = "";      var imagePath = "";    if ( IsPost )        {                    photo = WebImage . GetImageFromRequest ();             if ( photo != null )            { newFileName = Guid . NewGuid (). ToString() + "_" + Path . GetFileName ( photo . FileName );              imagePath = @"images\" + newFileName;               photo.Save(@"~\" + imagePath );            }        }     var FName="";     var LName="";     var MName="";     var gYear="";     var yourEmail="";     var country="";     var state="";     var city="";     var phone="";     var SCode="";     Validation.RequireField("formFName","Your First Name is missing");     //Validation.RequireField("formFName","Your First Name is missing");     Validation.RequireField("formLName","Your Last Name is missing");     Validation.RequireField("formYear","Your graduation year is unknown");     Validation.RequireField("formCountry","Please provide your country name");     Validation.RequireField("formState","Please provide your state of residence");     Validation.RequireField("formCity","Please in which city do you reside");     Validation.RequireField("formPhone","Please what is your phone number");     Validation.RequireField("formCode","Please provide your secure code");     //Validation.Add("formPhone",Validator.StringLength(15,11,"Invalid Phone Number"));     Validation.Add("formFName", Validator.StringLength(15,1,"Invalid First name"));     if(IsPost)       {           if (Validation.IsValid())           {         // Do something on the POST         //   MovieName=Request["formName"];          //  MovieGenre=Request["formGenre"];          //  MovieYear=Request["formYear"];            FName=Request["formFName"];            LName=Request["formLName"];            MName=Request["formMName"];            if (MName.IsEmpty())            {                MName="Null";            }            gYear=Request["formYear"];            yourEmail=Request["formEmail"];            country=Request["formCountry"];            state=Request["formState"];            city=Request["formCity"];            phone=Request["formPhone"];            SCode=Request["formCode"];            var SQLINSERT = "INSERT INTO wesley_profile (firstName,lastName,middleName,graduationYear,emailAddress,country,state,city,phone,creation) VALUES (@0, @1, @2,@3,@4,@5,@6,@7,@8,@9)";         var db = Database.Open("DbCon");         db.Execute(SQLINSERT, FName, LName, MName,gYear,yourEmail,country,state,city,phone,DateTime.Now);         Response.Redirect("default.cshtml");       }             } } @Render("PageHeader.cshtml")

    Page header Picture
    Thursday, June 6, 2013 3:47 PM

Answers

  • User-821857111 posted

    Have you actually checked with your hosting company to see if the package you are on supports ASP.NET? Often, code renders like that because the server your site is on is Linux instead of Windows.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 7, 2013 1:42 AM

All replies

  • User-1980594115 posted

    It seems that your page is not being recognized as using Razor syntax.  Are the page names ending in .cshtml?  When I ran your code, I received the following error:

    The code block is missing a closing "}" character.  Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.

    Hence you will also need to locate where the missing "}" is in your code.

     

    Thursday, June 6, 2013 4:46 PM
  • User281315223 posted

    I tried cleaning up things a bit although there are a variety of things that could possibly be going wrong : 

    @{     WebImage photo = null ;      
           var newFileName = "";      
           var imagePath = "";    
           if (IsPost)
           {
               photo = WebImage.GetImageFromRequest ();             
               if (photo != null)
               {
                   newFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(photo.FileName);              
                   imagePath = @"images\" + newFileName;               
                   photo.Save(@"~\" + imagePath );
               }
           }     
           var FName="";     
           var LName="";     
           var MName="";     
           var gYear="";     
           var yourEmail="";     
           var country="";     
           var state="";     
           var city="";     
           var phone="";     
           var SCode="";     
           
           Validation.RequireField("formFName","Your First Name is missing");     
           //Validation.RequireField("formFName","Your First Name is missing");     
           Validation.RequireField("formLName","Your Last Name is missing");     
           Validation.RequireField("formYear","Your graduation year is unknown");     
           Validation.RequireField("formCountry","Please provide your country name");     
           Validation.RequireField("formState","Please provide your state of residence");     
           Validation.RequireField("formCity","Please in which city do you reside");     
           Validation.RequireField("formPhone","Please what is your phone number");     
           Validation.RequireField("formCode","Please provide your secure code");     
           //Validation.Add("formPhone",Validator.StringLength(15,11,"Invalid Phone Number"));     
           Validation.Add("formFName", Validator.StringLength(15,1,"Invalid First name"));     
           if(IsPost)
           {           
               if (Validation.IsValid())
               {         
                   // Do something on the POST         
                   // MovieName=Request["formName"];          
                   // MovieGenre=Request["formGenre"];          
                   // MovieYear=Request["formYear"];            
                   FName=Request["formFName"];            
                   LName=Request["formLName"];            
                   MName=Request["formMName"];            
                   if (MName.IsEmpty())
                   {
                       MName="Null";
                   }            
                   gYear=Request["formYear"];            
                   yourEmail=Request["formEmail"];            
                   country=Request["formCountry"];            
                   state=Request["formState"];            
                   city=Request["formCity"];            
                   phone=Request["formPhone"];            
                   SCode=Request["formCode"];            
                   var SQLINSERT = "INSERT INTO wesley_profile (firstName,lastName,middleName,graduationYear,emailAddress,country,state,city,phone,creation) VALUES (@0, @1, @2,@3,@4,@5,@6,@7,@8,@9)";         
                   var db = Database.Open("DbCon");         
                   db.Execute(SQLINSERT, FName, LName, MName,gYear,yourEmail,country,state,city,phone,DateTime.Now);         
                   Response.Redirect("default.cshtml");       
               }             
           } 
    } 
    @RenderPage("PageHeader.aspx")

    The Razor syntax can be a bit tricky when it comes to how braces need to be used so you just need to be very careful and ensure that your closing and ending ones always match up.

    Thursday, June 6, 2013 5:01 PM
  • User-1272177930 posted

    Hi thanks,

    it renders properly on my development pc but not on the target host. I had even run a test to save data to my local db and it works fine.

     

    Thursday, June 6, 2013 6:28 PM
  • User-821857111 posted

    Have you actually checked with your hosting company to see if the package you are on supports ASP.NET? Often, code renders like that because the server your site is on is Linux instead of Windows.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 7, 2013 1:42 AM
  • User13850534 posted

    You need to make sure you uploaded all files properly to host server. Maybe you have to double check with support.

    Saturday, June 8, 2013 5:19 AM