Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在mvc3中为Ajax帖子添加值_Ajax_Asp.net Mvc 3_Jquery - Fatal编程技术网

在mvc3中为Ajax帖子添加值

在mvc3中为Ajax帖子添加值,ajax,asp.net-mvc-3,jquery,Ajax,Asp.net Mvc 3,Jquery,我需要将隐藏字段中的值添加到我的Ajax帖子中 恐怕我对Ajax了解不多,因此我将尝试解释我需要什么: 在我的查看页面中,我有以下内容: <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <div class="OneBySevenBin2"> <div class="OneBySevenBin2middle"> <div

我需要将隐藏字段中的值添加到我的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) %>

问题中的ajax
post
代码在哪里
getJSON
使用
GET
请求,您可以以任何方式添加隐藏字段数据,如

$.ajax({
 url:'',
 type:'',
 data:{hdnField:$("#e-taleWidgetImpressionId").val()},
 ...
});
在服务器端,它可以作为

         [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult OneBySevenBin2(String modelNo, string widgetImpressionId, string page, FormCollection form,string hdnField)
        {
         ...
         }

这就是MVC2,不是吗?MVC3将使用剃须刀
@
syntax@Liam这在mvc3中是不必要的,
@anna,dakit是对的,但是Razor使代码更加简洁。如果你想用这个,那很好,但也许读一下:谢谢@Liam我会的do@anna是否通过javascript设置隐藏字段的值?
  [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult OneBySevenBin2(String modelNo, string widgetImpressionId, string page, FormCollection form)
        {
...
}
$.ajax({
 url:'',
 type:'',
 data:{hdnField:$("#e-taleWidgetImpressionId").val()},
 ...
});
         [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult OneBySevenBin2(String modelNo, string widgetImpressionId, string page, FormCollection form,string hdnField)
        {
         ...
         }