webmatrix中的jQuery/Ajax简单表单发布 [英] jQuery/Ajax simple form post in webmatrix
问题描述
有人可以告诉我我需要的代码,以便此表单无需刷新即可更新数据库吗?
Can someone please tell me the code I need, so that this form updates the database without needing a refresh?
@{
Layout = "~/_template1.cshtml";
var db = Database.Open("stayinflorida");
var CurrentUser = WebSecurity.CurrentUserId;
var userdetails = ("SELECT * from UserProfile WHERE UserId='8'");
var quserdetails = db.QuerySingle(userdetails, CurrentUser);
if (IsPost){
var updateuserdetails = "UPDATE UserProfile SET FirstName = @0, LastName = @1 WHERE UserID='8'";
db.Execute(updateuserdetails, Request["FirstName"], Request["LastName"]);
}
}
<h1>My Details</h1>
<hr>
<form method="post" action="~/Account/MyDetails.cshtml">
<fieldset>
<label>First Name</label>
<input class="input-xlarge" type="text" name="FirstName" placeholder=".input-xlarge" value="@quserdetails.FirstName">
<br>
<label>Last Name</label>
<input class="input-xlarge" type="text" name="LastName" placeholder=".input-xlarge" value="@quserdetails.LastName">
<button type="submit" class="btn btn-success">Update</button>
<button type="submit" class="btn btn-success">Cancel</button>
</fieldset>
</form>
我写过的作品种类很多,但我必须按F5进行更新,而这并不是我想要的.我想使用jQuery/ajax,但我只是不知道代码.
What I have written kind of works, but I have to hit F5 for it to update, and it's just not what I want. I want to use jQuery/ajax, but I just don't know the code.
推荐答案
如果要使用AJAX,则需要一些JavaScript. jQuery库简化了这一过程.这是我写的一篇使用WebMatrix进行AJAX更新的文章:
You need some JavaScript if you want to use AJAX. The jQuery library simplifies this. Here's an article I wrote that features AJAX updates using WebMatrix: http://www.mikesdotnetting.com/Article/176/WebMatrix-and-jQuery-Forms-Part-2-Editing-Data
这篇关于webmatrix中的jQuery/Ajax简单表单发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!