最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to add or remove partial view Asp.net mvc with jquery? - Stack Overflow

programmeradmin0浏览0评论

I have a grid (Kendo grid), when occur edit function for any record of grid,I call a partial view with use of Jquery.Now i want after submit partial view, remove it from main view. My function for render partial view is :

  function ShowEditRecord(e) {
    var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
    $.ajax(
        {
            url: '/Home/TestEdit/'+dataItem.Id.toString(),
            contentType: 'application/html; charset=utf-8',
            type: 'Get',
            dataType: 'html'
        })
    .success(function(result)
    { $('#EditTestSection').html(result); })

My code of controller is :

   public ActionResult TestEdit(Int64 Id)
    {
        var modelItem=getT().Where(a => a.Id == Id).FirstOrDefault();
        return View (modelItem);
    }
    [HttpPost]
    public ActionResult TestEdit(Models.Test Test)
    {
        base.Update(Test);
        return View();
    }

After occur edit function :

I have a grid (Kendo grid), when occur edit function for any record of grid,I call a partial view with use of Jquery.Now i want after submit partial view, remove it from main view. My function for render partial view is :

  function ShowEditRecord(e) {
    var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
    $.ajax(
        {
            url: '/Home/TestEdit/'+dataItem.Id.toString(),
            contentType: 'application/html; charset=utf-8',
            type: 'Get',
            dataType: 'html'
        })
    .success(function(result)
    { $('#EditTestSection').html(result); })

My code of controller is :

   public ActionResult TestEdit(Int64 Id)
    {
        var modelItem=getT().Where(a => a.Id == Id).FirstOrDefault();
        return View (modelItem);
    }
    [HttpPost]
    public ActionResult TestEdit(Models.Test Test)
    {
        base.Update(Test);
        return View();
    }

After occur edit function :

Share Improve this question asked Aug 18, 2014 at 23:04 M.MohammadiM.Mohammadi 1,6671 gold badge14 silver badges26 bronze badges 1
  • Instead of returning a view on successful POST, return json with a success code return JSON(new { success = true }). Then in your AJAX success handler check this value to determine whether to clear your div. You can see a similar example here. – Jasen Commented Aug 19, 2014 at 0:07
Add a ment  | 

2 Answers 2

Reset to default 5

You can clear the markup from the partial view using empty():

$('#EditTestSection').empty();

Which you would include as part of your submit function.

jQuery's empty() function removes all child nodes and text of an element, so you can maybe use something like

$('#EditTestSection').empty();
发布评论

评论列表(0)

  1. 暂无评论