我需要将隐藏字段中的值添加到我的 Ajax 帖子中。
恐怕我对 Ajax 了解不多,所以我将尝试解释我需要什么:
在我的视图页面中,我有以下内容:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div class="OneBySevenBin2">
<div class="OneBySevenBin2middle">
<div class="divTitleArea">
<p>
</p>
</div>
<ul>
<% if (Model.ProductNotFound)
{ %>
<!-- List the retailers as we have none in stock -->
<%= Html.WidgetProductNotFoundList(Model) %>
<% }
else
{ %>
<% using (Html.BeginForm())
{%>
<%= Html.AntiForgeryToken() %>
<%= Html.WidgetProductFoundListThreeStageBin2(Model)%>
<div class="stepFour" data-bind="stopBinding: true">
<% if (string.IsNullOrEmpty(ViewBag.Confirmation))
{
Ajax.BeginForm("OneBySevenBin2", new AjaxOptions()
{
HttpMethod = "POST"
});
{ %>
<div id="uandp">
<p>
<input type="text" name="username" class="txtUsername" id="email" value="Username" />
<%= Html.ValidationMessage("Email", "Please enter a valid Email") %>
</p>
<p>
<input type="password" name="password" class="txtPassword" value="Password" />
</p>
<input type="hidden" id="hiddenVal" class="hiddenVal" name="hiddenVal" value="1" />
</div>
<div id="rightaddtocart">
<div id="divaddtocartbtn">
<input type="image" class="buynow" id="imgaddtocart" alt="Add to Cart" src="http://static.e-talemedia.net/content/images/addtobasketbutton.png" />
</div>
</div>
<% } %>
<% }
else
{ %>
<p>
<%-- <%= ViewBag.Confirmation %>--%>
<img class="divAdded" src="http://static.e-talemedia.net/content/images/Basketmessage.png"
alt="Added to Basket" />
</p>
<% } %>
</div>
<% } %>
<%-- This is the quantity--%>
<div class="qty">
<button id="delete" class="minusQty">
</button>
<div id="theCount" class="theCount">
</div>
<button id="addMe" class="addQty">
</button>
</div>
<% } %>
</ul>
</div>
</div>
<%= Html.WidgetImpressionCode(Model) %>
<%= Html.WidgetTrackingCode(Model) %>
以下:
<%= Html.WidgetImpressionCode(Model) %>
转到省略脚本的小部件助手,如下所示:
<input id="e-taleWidgetImpressionId" name="e-taleWidgetImpressionId" type="hidden" value="" />
<script type="text/javascript">
//<![CDATA[
$(document).ready(function () {
var manufacturerWidgetId = "260";
var productId = "6572";
var countryId = "230";
var theUrl = "http://localhost:1579/Widgets/Impression/260/6572/230/9r22r45r80";
$.getJSON(theUrl + "?callback=?", {}, callback);
function callback(data) {
var widgetImpressionId = data.Id;
$("input[name='e-taleWidgetImpressionId']").val(widgetImpressionId);
}
});
//]]>
</script>
我需要在 ajax 帖子中包含隐藏字段的值
<input id="e-taleWidgetImpressionId" name="e-taleWidgetImpressionId" type="hidden" value="" />
这样我就可以在控制器中使用它:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult OneBySevenBin2(String modelNo, string widgetImpressionId, string page, FormCollection form)
{
...
}