Jquery 在Ajax.BeginForm中传递UpdateTargetId而不替换目标

Jquery 在Ajax.BeginForm中传递UpdateTargetId而不替换目标,jquery,html,ajax,asp.net-mvc,asp.net-web-api,Jquery,Html,Ajax,Asp.net Mvc,Asp.net Web Api,在Ajax.BeginForm中,尽管我已经指定了targetId,它是我的部分视图,但它正在替换完整视图。我错过什么了吗 ProductList.cshtml <div class="form-style-1" style="float:left"> @using (Ajax.BeginForm("SearchProducts", "Product", new AjaxOptions() { HttpMethod="

在Ajax.BeginForm中,尽管我已经指定了targetId,它是我的部分视图,但它正在替换完整视图。我错过什么了吗

ProductList.cshtml

<div class="form-style-1" style="float:left">
           @using (Ajax.BeginForm("SearchProducts", "Product", new AjaxOptions()
           {
           HttpMethod="POST",
           InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace,
           UpdateTargetId = "product-list-container"
           }))
           {
           <form>
              <input name="SearchText" id="SearchText" class="field-divided" style="width: 300px;" type="text" />
              <input type="submit" value="Search" class="myButton" />
           </form>
           }
        </div>@Html.Partial("ListPartialView", Model)


ListPartialView.cshtml - 

<div id="product-list-container">
    @foreach (var product in Model)
    {
        <div class="product_box margin_r40">
            <div class="thumb_wrapper"><a><img src="@Url.Content(@product.ImagePath)" alt="image 1" /></a></div>
            <h3>@product.ProductName</h3>
            <p>@product.Description</p>
        </div>
    }
    <div class="button_01"><a href="#">View All</a></div>
    <div class="cleaner"></div>
</div>

@使用(Ajax.BeginForm(“SearchProducts”、“Product”、新的AjaxOptions())
{
HttpMethod=“POST”,
InsertionMode=System.Web.Mvc.Ajax.InsertionMode.Replace,
UpdateTargetId=“产品列表容器”
}))
{
}
@Html.Partial(“ListPartialView”,模型)
ListPartialView.cshtml-
@foreach(模型中的var乘积)
{
SearchProducts-控制器操作

[HttpPost]
        public ActionResult SearchProducts()
        {
            var searchTxt = Request.Form["SearchText"];                                                
            IEnumerable<Product> searchedProducts = (from p in dal.Products
                                                     where p.ProductName.Contains(searchTxt) ||
                                                     p.Description.Contains(searchTxt)
                                                     select p).ToList();

            return PartialView("ListPartialView", searchedProducts);
        }
[HttpPost]
公共行动结果搜索产品()
{
var searchTxt=Request.Form[“SearchText”];
IEnumerable searchedProducts=(来自dal.Products中的p
其中p.ProductName.Contains(searchTxt)||
p、 Description.Contains(searchTxt)
选择p.ToList();
返回PartialView(“ListPartialView”,searchedProducts);
}

确保页面/布局中包含
jquery.unobtrusive ajax.js

<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>

此文件使您的表单成为ajaxified


如果您没有包含此文件,则您的表单将是普通表单。单击“提交”按钮将执行普通表单提交,这可能是您看到整个页面的原因。

我已将其包含在主页中。这是我检查的第一件事。jQuery脚本排序错误,请从控制台中找出原因。非常感谢。