简体   繁体   English

mvc razor 在操作后不会重定向到 url

[英]mvc razor does not redirect to url after action

I want to open Edit page of a product but after Index action it does not redirect to that page from list page.我想打开产品的编辑页面,但在索引操作后它不会从列表页面重定向到该页面。 Here you can find my codes:在这里你可以找到我的代码:

On my List page:在我的列表页面上:

    function getProductDetail(id) {

        $.ajax({
            type: "POST",
            url: '@Url.Action("Index","ProductDetail")',
            dataType: "html",
            data: JSON.stringify({ "productId": id }),
            contentType: "application/json",
            success: function (result) {

            }
        });
    }
</script>

And on my ProductDetailController:在我的 ProductDetailController 上:

   public ActionResult Index(int productId)
        {

            Product prod = GetProductDetail(productId);

            return View(prod);
        }

As per the comments above, you don't need to use AJAX at all in this situation.根据上面的评论,在这种情况下您根本不需要使用 AJAX。 If you were planning to dynamically update the DOM, using an asynchronous call to the server, this would make sense.如果您计划使用对服务器的异步调用来动态更新 DOM,这将是有意义的。 In your case, since you are just redirecting to the page, it would make more sense to use an actionlink and get rid of the AJAX call completely.在您的情况下,由于您只是重定向到页面,因此使用 actionlink 并完全摆脱 AJAX 调用会更有意义。

@HTML.ActionLink("Link Text","Index","ProductDetail",new {productId = "1234"}, null))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM