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")
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.
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.
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.
Member
1 Points
6 Posts
Cshtml pages not rendered properly
Jun 06, 2013 03:47 PM|SoftPower|LINK
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")
<div id="banner">Member
690 Points
185 Posts
Re: Cshtml pages not rendered properly
Jun 06, 2013 04:46 PM|dblaire|LINK
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.
All-Star
114593 Points
18503 Posts
MVP
Re: Cshtml pages not rendered properly
Jun 06, 2013 05:01 PM|Rion Williams|LINK
I tried cleaning up things a bit although there are a variety of things that could possibly be going wrong :
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.
Member
1 Points
6 Posts
Re: Cshtml pages not rendered properly
Jun 06, 2013 06:28 PM|SoftPower|LINK
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.
All-Star
194016 Points
28029 Posts
Moderator
Re: Cshtml pages not rendered properly
Jun 07, 2013 01:42 AM|Mikesdotnetting|LINK
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.
Contributor
2560 Points
926 Posts
Re: Cshtml pages not rendered properly
Jun 08, 2013 05:19 AM|Topspy|LINK
You need to make sure you uploaded all files properly to host server. Maybe you have to double check with support.