如何使用POST请求从操作中重定向用户?
我有:
public ViewResult AddMoneyOnPay()
{
Onpay onpay = new Onpay();
onpay.convert = "yes";
onpay.pay_mode = "fix";
onpay.price_final = "true";
return View(onpay);
}
查看:
@using (Html.BeginForm("AddMoneyOnPay", "Transaction", FormMethod.Post))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Onpay</legend>
<div class="editor-field">
@Html.EditorFor(model => model.pay_mode)
@Html.ValidationMessageFor(model => model.pay_mode)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.price)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.price)
@Html.ValidationMessageFor(model => model.price)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.currency)
@Html.ValidationMessageFor(model => model.currency)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.pay_for)
@Html.ValidationMessageFor(model => model.pay_for)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.md5)
@Html.ValidationMessageFor(model => model.md5)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.convert)
@Html.ValidationMessageFor(model => model.convert)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.url_success)
@Html.ValidationMessageFor(model => model.url_success)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.url_fail)
@Html.ValidationMessageFor(model => model.url_fail)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.user_email)
@Html.ValidationMessageFor(model => model.user_email)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.note)
@Html.ValidationMessageFor(model => model.note)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.one_way)
@Html.ValidationMessageFor(model => model.one_way)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.price_final)
@Html.ValidationMessageFor(model => model.price_final)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.direct_no)
@Html.ValidationMessageFor(model => model.direct_no)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
动作POST
[HttpPost]
public ViewResult AddMoneyOnPay(Onpay onpay)
{
string secretKEy = "fH12312IO";
onpay.md5 = GetHash(string.Format("{0};{1};{2};{3};{4}", onpay.pay_mode, onpay.price, onpay.currency, onpay.pay_for, onpay.convert, secretKEy));
//SEND POST to url http://paysite.ru/blablabla
}
答案 0 :(得分:1)
让AddMoneyOnPay
方法返回ActionResult
,然后写:
return Redirect(returnUrl);