0

我尝试了一些东西。我为我的英语提前道歉。是不是我想要PartialViewResult的方式

我的动作代码;

public PartialViewResult showProduct() 
{ 

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

我的视图代码:

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

当我按下提交按钮(这值获得)返回结果,但在像http://localhost:57616/Home/showProduct另一个页面,但我想回导致索引页格。

任何人都可以帮助我吗?

回答

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)提交。

+0

我不想用javascript :( –

+0

请参阅我在答案底部添加的注释。 – itsmatt

相关问题