2010-12-22 28 views
0

我正在寫一些有關添加和編輯表單的基於Castle MonoRail的站點。添加表單工作正常,並使用POST,但編輯表單使用GET。我可以看到唯一的主要區別是編輯方法是通過在查詢字符串中編輯對象的Id來調用的。當在編輯表單上按下提交按鈕時,唯一傳遞的參數是該對象標識。下面是編輯形式的代碼:單軌 - 使用GET而不是POST提交表單

<form action="edit.ashx" method="post"> 
<h3>Coupon Description</h3> 
<textarea name="comments" width="200">$comments</textarea> 
<br/><br/> 
<h3>Coupon Actions</h3> 
<br/> 
<div>Give Stories</div> 

<ul class="checklist" style="overflow:auto;height:144px;width:100%"> 
#foreach ($story in $stories.Values) 
    <li> 
    <label> 
    #set ($associated = "") 
    #foreach($storyId in $storyIds) 
     #if($story.Id == $storyId) 
      #set($associated = " checked='true'") 
     #end 
    #end 
    <input type="checkbox" name="chk_${story.Id}" id="chk_${story.Id}" value="true" class="checkbox" $associated/> 
    $story.Name 
</label> 
</li> 
#end 
</ul> 
    <br/><br/> 
<div>Give Credit Amount</div> 
<input type="text" name="credit" value="$credit" /> 
<br/><br/> 

<h3>Coupon Uses</h3> 
<input type="checkbox" name="multi" #if($multi) checked="true" #end /> Multi-Use Coupon?<br/><br/> 
<b>OR</b> 
<br/> 
<br/> 
Number of Uses per Coupon: <input type="text" name="uses" value="$uses" /> 
<br/> 

<input type="submit" name="Save" /> 

</form> 

這個和附加形式之間的差異是速度東西做與關聯和輸入從所述的PropertyBag作爲值。

方法,採用此控制器上的處理開始是這樣的:

public void Edit(int id) 
{ 
    Coupon coupon = Coupon.GetRepository(User.Site.Id).FindById(id).Value; 
    if(coupon == null) { 
     RedirectToReferrer(); 
     return; 
    } 

    IFutureQueryOfList<Story> stories = Story.GetRepository(User.Site.Id).OnlyReturnEnabled().FindAll("Name", true); 

    if (Params["Save"] == null) 
    { 
     ... 
    } 
} 

它可靠地被調用,但存在params [「保存」]斷點讓我看到,列舉HTTPMethod是「GET」和只有傳遞的參數(在表單和請求中)是對象標識和附加的HTTP標題。

在一天結束的時候,我對MonoRail並不熟悉,這可能代表我的一個愚蠢的錯誤,但是我會非常感謝如果它解決了問題,我就會被愚弄掉! :)

感謝

+0

我可以看到這段代碼有一些錯誤的東西,但具體的問題是什麼? – 2010-12-22 12:07:25

回答

0

我身邊這讓使用一個單獨的方法在控制器上處理保存優惠券,而不是一個兩個裝載形式和處理它的提交。