Monorail - 使用GET而不是POST提交表单

时间:2010-12-22 09:29:07

标签: http post get castle-monorail

我正在为基于Castle MonoRail的网站添加一些内容,其中包含添加和编辑表单。添加表单工作正常并使用POST,但编辑表单使用GET。我能看到的唯一主要区别是,在查询字符串中使用正在编辑的对象的Id调用edit方法。在编辑表单上按下提交按钮时,唯一传递的参数是该对象Id。以下是编辑表单的代码:

<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 [“Save”]上的断点让我看到HttpMethod是“GET”并且传递的唯一参数(在Form和Request中)是对象Id和其他HTTP头。

在一天结束的时候,我对MonoRail并不熟悉,这对我来说可能是一个愚蠢的错误,但如果能解决这个问题,我会非常感谢你被愚弄了! :)

由于

1 个答案:

答案 0 :(得分:0)

我通过在控制器上使用一个单独的方法处理保存优惠券而不是一个用于加载表单和处理它的提交来解决这个问题。

相关问题