Monorail-使用Get而不是邮寄的表单提交
-
12-10-2019 - |
题
我正在写一些基于添加和编辑表格的基于城堡的网站。添加表单正常运行并使用帖子,但编辑表单使用获取。我可以看到的唯一主要区别是,调用编辑方法是在查询字符串中编辑的对象的ID调用。当在编辑表单上按下提交按钮时,唯一传递的参数再次是此对象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>
此和添加形式之间的差异是与关联有关的速度内容以及来自属性袋的输入值。
在控制器上处理此问题的方法是这样开始的:
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)
{
...
}
}
它可靠地被调用,但是在参数[“ save”]上的断点让我看到httpmethod是“ get”,而唯一传递的参数(在表单和请求中)是对象ID和其他HTTP标头。
归根结底,我对Monorail并不那么熟悉,这可能是一个愚蠢的错误,但我非常感谢如果解决问题,我会被愚弄! :)
谢谢
解决方案
我通过在控制器上使用单独的方法来处理保存优惠券,而不是为了加载表单和处理其提交的内容来解决这个问题。
不隶属于 StackOverflow