0

我正在为基于 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”,并且传递的唯一参数(在表单和请求中)是对象 ID 和其他 HTTP 标头。

归根结底,我对 MonoRail 并不熟悉,这对我来说可能是一个愚蠢的错误,但如果它能解决问题,我将非常感激被愚弄!:)

谢谢

4

1 回答 1

0

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

于 2011-01-04T08:51:15.637 回答