Hello,
I just created a basic app that fetches records from a db with an edit page.
I understand that my code is a bit messed up and would like it if you could tell me where did I go wrong with it.
This is my code for EditArticles.cshtml
@{
Layout = "../Shared/_AdminPanelLayout.cshtml";
}
<div class="right_content">
<h2>Add Article</h2>
<div class="form">
<form action="" method="post" class="niceform">
@{
var id = Request["id"];
var SQLSELECT = "SELECT * FROM Articles where ArticleID=@0";
var db = Database.Open("ContosoKaratePRM");
var Article = db.QuerySingle(SQLSELECT, id);
var Title = Article.ArticleTitle;
var Body = Article.ArticleBody;
var Date = Article.ArticleDate;
var User = Article.UserID;
if(IsPost)
{
Title = Request["formTitle"];
Body = Request["formBody"];
Date = DateTime.Now;
User = Request["formAuthorID"];
var SQLUPDATE = "UPDATE Articles SET ArticleTitle=@0, ArticleBody=@1, ArticleDate=@2, UserID=@3 WHERE id=@4";
db.Execute(SQLUPDATE, Title, Body, Date, User, id);
Response.Redirect("ViewArticles.cshtml");
}
else {
<fieldset>
<dl>
<dt><label for="Title">Article Title</label></dt>
<dd><input type="text" name="formTitle" id="" size="54" value="@Title" /></dd>
</dl>
<dl>
<dt><label for="gender">Select Author:</label></dt>
<dd>
<select size="1" name="formAuthorID" id="">
<option value="@User">@User</option>
</select>
</dd>
</dl>
<dl>
<dt><label for="comments">Article Body:</label></dt>
<dd><textarea name="formBody" id="comments" rows="25" cols="45">@Body</textarea></dd>
</dl>
<dl class="submit">
<input type="submit" name="submit" id="submit" value="Submit" />
</dl>
</fieldset>
}
}
</form>
</div>
</div><!-- end of right content-->
What I wanna do here is display all the users in the dropdown menu found in table UserProfile and display the correct author of that article on that dropdown menu.
How can I do that?
These are my tables and fields:
- Articles
--ArticleID
--ArticleTitle
--ArticleDate
--ArticleBody
--UserID
-UserProfile
--Email
--UserId