如果数据库中已存在数据,我无法在文本字段中获取数据。
问题:我想在页面加载时将数据放在输入标记的文本字段中。因此,编辑特定字段可能很容易。
@{
Page.Title = "Edit Record | Student Registration System ";
var id = Request.QueryString["id"];
var info = UrlData[0];
Validation.RequireField("Student_Reg_No", "Student Reg No is required.");
if (info.IsEmpty())
{
Response.Redirect("~/default");
}
else if (IsPost) {
var value = Request.Form["value"];
var Student_Reg_No = Request.Form["Student_Reg_No"];
if (Validation.IsValid()){
// try{
var db = Database.Open("site_data");
var updateCommand = "Update site_data_table set Student_Reg_No =@0, Student_Name=@1 where Student_Reg_No=@0";
db.Execute(updateCommand, Student_Reg_No);
Response.Redirect(@Href("~/default"));
@Href("~/ edit.cshtml ", @value);
}
}
else {
var db1 = Database.Open("site_data");
var row = db1.QuerySingle("SELECT * FROM site_data_table WHERE Id =@0", info);
var value = row.id;
var Student_Reg_No = row.Student_Reg_No;
<textarea>hi aasdasd</textarea>
}
}
从这里开始HTML部分
<form method="post">
<table>
<input type="text" name="value" value="@Request.Form["value"]"
<tr>
<label for="Student_Reg_No">Student Reg No:</label> </br>
<input type="text" name="Student_Reg_No" value="@Request.Form["Student_Reg_No"]" />
<span class="error"> @Html.ValidationMessage("Student_Reg_No") </span>
</tr></br>
<p><input type="submit" name="buttonSubmit" value="Add Movie" /></p>
</table>
</form>