0

I try something.I apologize in advance for my english.

My Action code;

public PartialViewResult showProduct()
{

    var query = db.Categories.Where((c) => c.CategoryID == 4);
    return PartialView("_EditCategory",query);
}

My view code:

 @using (Ajax.BeginForm(
    "showProduct",
    new AjaxOptions
    {
        HttpMethod = "GET",
        InsertionMode = InsertionMode.InsertAfter,
        UpdateTargetId = "result"
    }))
    {
       <input type="submit" value="Get" />
    }
    <div id="result">
    </div>

When i pushed the submit button ( which value is get) the results return but in another page like http://localhost:57616/Home/showProduct but i want return to result div in index page.

Any one can help me?

4

1 回答 1

1

所以,我自己的处理方式是这样的:

$(document).ready(function () {
var options = {
   target: "#mytargetdiv",
   url: '@Url.Action("Edit", "IceCream")',
};

$("#editIceCreamForm").submit(function () {
   $(this).ajaxSubmit(options);
   return false;
}

// other stuff

});

在其他地方,我想对事情进行就地编辑,我会这样做:

<input type="button" id="someid" value="Edit" data-someid="@Model.SomeId"/>

然后是一些像这样的ajax:

$(function () {
   $("#someid".click(function () {
      var theId = $(this).data('someid');
      $.ajax({
         type: "GET",
         data: "id=" + theId,
         url: '@Url.Action("Edit", "Something")',
         dataType: "html",
         success: function (result) {
            $('#targetdiv').html(result);
         }
      });
   });
});

所以,如果您对使用 jQuery 不感兴趣,并且想使用 MS Ajax 的东西,您是否在页面上包含 MicrosoftAjax.js 和 MicrosoftMvcAjax.js 文件?如果您没有这些,我相信会发生什么,它只是执行默认(非 Ajax)提交。

于 2011-10-24T14:54:21.393 回答