1
我想在一個頁面上有兩個表單,每個表單更新我數據庫中的不同數據。我如何獲得一個提交按鈕來運行一個UPDATE查詢,而另一個窗體運行另一個?2個表格,1頁 - WebMatrix/Razor
我創建了一個測試頁面,但我沒有運氣。我猜我需要命名每個表單,然後爲每個表單創建2個if(ispost)語句?
這是我到目前爲止有:
@{
Layout = "~/_template1.cshtml";
Page.Title = "Add Property";
var db = Database.Open("StayInFlorida");
var propertyinfo = "SELECT * FROM PropertyInfo WHERE PropertyID='8'";
var propinfo = db.QuerySingle(propertyinfo);
if (IsPost){
var form1 = "UPDATE PropertyInfo SET PropertyName = @0, PropertyWebSite = @1 WHERE PropertyID='8'";
db.Execute(form1, Request["PropertyName"], Request["PropertyWebsite"]);
}
if (IsPost){
var form2 = "UPDATE PropertyInfo SET NumBedrooms = @0, NumBathrooms = @1 WHERE PropertyID='8'";
db.Execute(form2, Request["NumBedrooms"], Request["NumBathrooms"]);
}
}
<hr>
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active"><a href="#tab1" data-toggle="tab">Tab1</a></li>
<li><a href="#tab2" data-toggle="tab">tab2</a></li>
</ul>
<!--Tab Content-->
<div class="tab-content">
<div id="tab1" class="tab-pane active">
<form method="post" action="">
<fieldset>
<label>Property Name:</label>
<input class="input-xlarge" type="text" name="PropertyName" placeholder=".input-xlarge" value="@propinfo.PropertyName">
<br>
<label>Property Website:</label>
<input class="input-xlarge" type="text" name="PropertyWebsite" placeholder=".input-xlarge" value="@propinfo.PropertyWebsite">
<br>
<button type="submit" class="btn btn-success">Update</button>
</fieldset>
</form>
</div>
<div id="tab2" class="tab-pane">
<form method="post" action="">
<fieldset>
<label>Number of Bedrooms:</label>
<input class="input-xlarge" type="text" name="NumBedrooms" placeholder=".input-xlarge" value="@propinfo.NumBedrooms">
<br>
<label>Number of Bathrooms:</label>
<input class="input-xlarge" type="text" name="NumBathrooms" placeholder=".input-xlarge" value="@propinfo.NumBathrooms">
<br>
<button type="submit" class="btn btn-success">Update</button>
</fieldset>
</form>
</div>
</div>
</div>
<hr>
謝謝,加文
應該每個按鈕的每個表單都有唯一的名稱和值? – Gavin5511 2013-04-11 15:53:02
忽略最後的評論,作品,再次感謝 – Gavin5511 2013-04-11 15:55:29