【发布时间】:2012-10-23 20:20:27
【问题描述】:
我尝试确认销售,我需要有关产品的总和信息..
我的观点
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Card</legend>
<div class="editor-label">
@Html.LabelFor(model => model.CardModel.SerialNumber, "Serial No")
</div>
<div class="editor-field">
@Html.EditorFor(model => model.CardModel.SerialNumber, new { id = "sn" })
@Html.ValidationMessageFor(model => model.CardModel.SerialNumber)
</div>
<p>
<input type="submit" value="CardSale" id="btnSubmit"
onclick="if (confirm('The owner dealer price is : **@Model.OwnerPrice** . Are you sure?')) { return true; } else { return false; }" />
</p>
</fieldset>
}
我尝试了这样的“$.getJSON”:
<script type="text/javascript">
$(document).ready(function()
{
$("#btnSubmit").click(function ()
{
var serial = $("#sn");
var price = "";
var url = "";
url = "@Url.Action("GetOwnerPrice","Card")/"+serial;
$.getJSON(url,function(data)
{
alert(data.Value);
});
});
});
在控制器上
public ActionResult GetOwnerPrice(int sn)
{
var owner = db.Dealers.Single(s => s.DealerID == db.Dealers.Single(o => o.UserName == User.Identity.Name).OwnerDealerID);
var ownerPrice = owner.ProductToSale.Single(pr => pr.ProductID == sn).SalePrice;
return Json(ownerPrice, JsonRequestBehavior.AllowGet);
}
但我不知道如何将其返回到 onclick 确认消息或返回到我的 ViewModel..
有什么帮助吗?
【问题讨论】:
-
GetOWnerPrice应该是JsonAction而不是ActionResult。关于返回的 json,我不确定它是否像您的想法,因为您将SalePrice传递给ownerPrice -
10x 我会尝试它,但它在 actionresult 之前可以工作。现在我不知道如何在我的虚拟机或确认消息中使用这个 ownerprice(提交-onclick)
-
为什么是 json?为什么不做一个正常形式的帖子? onclick="... 是怎么回事?这对我来说看起来不合法。
-
onclick完全不应该在那里...... -
因为我想在发布之前发出警报,如果经销商看到他的成本高于他出售它 - 他会点击取消,我们不会发布它..
标签: c# jquery asp.net-mvc razor