I am fairly new to razor syntax but have solid experience in HTML and CSS. I am building a page that will be used to store the users information. I want to perform the following tasks...
1) Have a user add their basic profile information, using the following rows in a table.
- FirstName, LastName, CompanyName, Address1, Address2, City, State, Zip, OfficePhone, MobilePhone
2) Once added, I want it to display in the input text boxes when the user is logged in and on the profile page
3) If the user has an update, I want them to be able to make the correction in the input text box and click on a button that updates that record
I have linked the UserId in the UserProfile table to a new table that would contain the profile information. This code I have so far but I know I am not headed in the right direction. I know I am missing the update command...I don't have the insert command
because I do not want to add a row each time a change is made.
@{
Layout = "~/_SiteLayout.cshtml";
Page.Title = "Profile";
var FirstName = "";
var LastName = "";
var CompanyName = "";
var Address1 = "";
var Address2 = "";
var City = "";
var State = "";
var Zip = "";
var OfficePhone = "";
var MobilePhone = "";
var ProfileId = "";
if(IsPost) {
if (Request.QueryString["UserID"].IsEmpty())
{
ProfileId = Request.QueryString["UserID"];
var db = Database.Open("Mumba_Data");
var dbCommand = "SELECT * FROM ProfileInfo WHERE ProfileId = @0";
var row = db.QuerySingle(dbCommand, ProfileId);
FirstName = row.FirstName;
LastName = row.LastName;
CompanyName = row.CompanyName;
Address1 = row.Address1;
Address2 = row.Address2;
City = row.City;
State = row.State;
Zip = row.Zip;
OfficePhone = row.OfficePhone;
MobilePhone = row.MobilePhone;
ProfileId = row.ProfileId;
}
}
if(IsPost) {
if (Request.QueryString["UserID"].IsEmpty())
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Profile</title>
</head>
<body>
<h1>Profile</h1>
<form method="post" action="Profile">
<fieldset>
<legend>Profile Information</legend>
<p><label for="FirstName">First Name:</label>
<input type="text" name="FirstName" value="@Request.QueryString["FirstName"]" />
</p>
<p><label for="LastName">Last Name:</label>
<input type="text" name="LastName" value="@Request.QueryString["LastName"]" />
</p>
<p><label for="Company">Company:</label>
<input type="text" name="CompanyName" value="@Request.QueryString["CompanyName"]" />
</p>
<p><label for="Address1">Address:</label>
<input type="text" name="Address1" value="@Request.QueryString["Address1"]" />
</p>
<p><label for="Address2">Unit:</label>
<input type="text" name="Address2" value="@Request.QueryString["Address2"]" />
</p>
<p><label for="City">City:</label>
<input type="text" name="City" value="@Request.QueryString["City"]" />
</p>
<p><label for="State">State:</label>
<input type="text" name="State" value="@Request.QueryString["State"]" />
</p>
<p><label for="Zip">Zip:</label>
<input type="text" name="Zip" value="@Request.QueryString["Zip"]" />
</p>
<p><label for="OfficePhone">Office Phone:</label>
<input type="text" name="OfficePhone" value="@Request.QueryString["OfficePhone"]" />
</p>
<p><label for="MobilePhone">Mobile Phone:</label>
<input type="text" name="MobilePhone" value="@Request.QueryString["MobilePhone"]" />
</p>
<input type="hidden" name="ProfileId" value="@ProfileId" />
<p><input type="submit" name="buttonSubmit" value="Save" /></p>
</fieldset>
</form>
</body>
</html>
I would greatly appreciate any help, direction to a tutorial or sample code. I have been using the the tutorials for Web Pages but I was hoping to get a little additional help.
Thanks. I have been working with these tutorials and find them very helpful. Do you know how I can insert just one row of data per user and then manage the data through updates after the profile has been set-up? I believe I have to use the INSERT command
but I want to disable the command once complete and only use UPDATE from that point forward.
kookoomoo
Member
54 Points
92 Posts
Web Pages, Inserting, Viewing and Updating Data
Jul 20, 2012 11:37 AM|LINK
Hi,
I am fairly new to razor syntax but have solid experience in HTML and CSS. I am building a page that will be used to store the users information. I want to perform the following tasks...
1) Have a user add their basic profile information, using the following rows in a table.
- FirstName, LastName, CompanyName, Address1, Address2, City, State, Zip, OfficePhone, MobilePhone
2) Once added, I want it to display in the input text boxes when the user is logged in and on the profile page
3) If the user has an update, I want them to be able to make the correction in the input text box and click on a button that updates that record
I have linked the UserId in the UserProfile table to a new table that would contain the profile information. This code I have so far but I know I am not headed in the right direction. I know I am missing the update command...I don't have the insert command because I do not want to add a row each time a change is made.
@{ Layout = "~/_SiteLayout.cshtml"; Page.Title = "Profile"; var FirstName = ""; var LastName = ""; var CompanyName = ""; var Address1 = ""; var Address2 = ""; var City = ""; var State = ""; var Zip = ""; var OfficePhone = ""; var MobilePhone = ""; var ProfileId = ""; if(IsPost) { if (Request.QueryString["UserID"].IsEmpty()) { ProfileId = Request.QueryString["UserID"]; var db = Database.Open("Mumba_Data"); var dbCommand = "SELECT * FROM ProfileInfo WHERE ProfileId = @0"; var row = db.QuerySingle(dbCommand, ProfileId); FirstName = row.FirstName; LastName = row.LastName; CompanyName = row.CompanyName; Address1 = row.Address1; Address2 = row.Address2; City = row.City; State = row.State; Zip = row.Zip; OfficePhone = row.OfficePhone; MobilePhone = row.MobilePhone; ProfileId = row.ProfileId; } } if(IsPost) { if (Request.QueryString["UserID"].IsEmpty()) } <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Profile</title> </head> <body> <h1>Profile</h1> <form method="post" action="Profile"> <fieldset> <legend>Profile Information</legend> <p><label for="FirstName">First Name:</label> <input type="text" name="FirstName" value="@Request.QueryString["FirstName"]" /> </p> <p><label for="LastName">Last Name:</label> <input type="text" name="LastName" value="@Request.QueryString["LastName"]" /> </p> <p><label for="Company">Company:</label> <input type="text" name="CompanyName" value="@Request.QueryString["CompanyName"]" /> </p> <p><label for="Address1">Address:</label> <input type="text" name="Address1" value="@Request.QueryString["Address1"]" /> </p> <p><label for="Address2">Unit:</label> <input type="text" name="Address2" value="@Request.QueryString["Address2"]" /> </p> <p><label for="City">City:</label> <input type="text" name="City" value="@Request.QueryString["City"]" /> </p> <p><label for="State">State:</label> <input type="text" name="State" value="@Request.QueryString["State"]" /> </p> <p><label for="Zip">Zip:</label> <input type="text" name="Zip" value="@Request.QueryString["Zip"]" /> </p> <p><label for="OfficePhone">Office Phone:</label> <input type="text" name="OfficePhone" value="@Request.QueryString["OfficePhone"]" /> </p> <p><label for="MobilePhone">Mobile Phone:</label> <input type="text" name="MobilePhone" value="@Request.QueryString["MobilePhone"]" /> </p> <input type="hidden" name="ProfileId" value="@ProfileId" /> <p><input type="submit" name="buttonSubmit" value="Save" /></p> </fieldset> </form> </body> </html>I would greatly appreciate any help, direction to a tutorial or sample code. I have been using the the tutorials for Web Pages but I was hoping to get a little additional help.
Thanks!
RAZOR sql
Mudasir.Khan
All-Star
15346 Points
3142 Posts
Re: Web Pages, Inserting, Viewing and Updating Data
Jul 20, 2012 02:33 PM|LINK
please check this you may follow the same pattern or atleast get an idea how to go ahead
http://www.asp.net/mvc/tutorials/older-versions/models-(data)/creating-model-classes-with-the-entity-framework-cs
http://www.c-sharpcorner.com/UploadFile/krishnasarala/select-insert-update-and-delete-with-Asp-Net-mvc/
http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/crud-operation-in-Asp-Net-mvc-framework/
RAZOR sql
Mikesdotnett...
All-Star
154901 Points
19864 Posts
Moderator
MVP
Re: Web Pages, Inserting, Viewing and Updating Data
Jul 20, 2012 02:58 PM|LINK
There are a series of Web Pages data-related tutorials here: http://www.asp.net/web-pages/tutorials
RAZOR sql
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
Mikesdotnett...
All-Star
154901 Points
19864 Posts
Moderator
MVP
Re: Web Pages, Inserting, Viewing and Updating Data
Jul 20, 2012 02:59 PM|LINK
They are all MVC related posts. The Web Pages framework is completely different.
RAZOR sql
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
kookoomoo
Member
54 Points
92 Posts
Re: Web Pages, Inserting, Viewing and Updating Data
Jul 20, 2012 05:05 PM|LINK
Thanks. I have been working with these tutorials and find them very helpful. Do you know how I can insert just one row of data per user and then manage the data through updates after the profile has been set-up? I believe I have to use the INSERT command but I want to disable the command once complete and only use UPDATE from that point forward.
Mikesdotnett...
All-Star
154901 Points
19864 Posts
Moderator
MVP
Re: Web Pages, Inserting, Viewing and Updating Data
Jul 20, 2012 06:01 PM|LINK
Ideally, you provide one page for adding a new user, and another for editing an existing user.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
kookoomoo
Member
54 Points
92 Posts
Re: Web Pages, Inserting, Viewing and Updating Data
Jul 20, 2012 07:17 PM|LINK
Thanks!