Server Error in '/' Application in .net mvc

Rahul Patil 46 Reputation points
2022-12-10T11:02:43.177+00:00

I am working with .net mvc i give the proper url name but error is the resource is not found

i am click the checkout button and trying to open view but view is not open

please see below code

cartDisplay.cshtml

@{  
    ViewBag.Title = "cartDisplay";  
}  
  
<h2>Add to Cart Details</h2>  
  
<script src="~/kendo/js/kendo.all.min.js"></script>  
  
<div style="display: inline">  
    <div class="text-left">  
        <button class='btn btn-group-sm btn-success' onclick='submit()'>CheckOut</button>  
    </div>  
</div>  
  
<div id="example">  
  
    <br />  
    <br />  
  
    <div id="grid"></div>  
  
    <script>  
        $(document).ready(function () {  
  
        //here other code  
        
      function submit() {  
            debugger  
            $.ajax({  
                url: "/User/addToCartOrderStore",           //here I am giving the proper url but error is resource not found error  
                type: 'GET',  
                cache: false,  
                contentType: false,  
                processData: false,  
  
                success: function (response) {  
                    window.location.href = response.redirectToUrl;  
                }  
            });  
        }  
    </script>  

UserController.cs

        //Shipping Details and order details  
        [HttpGet]  
        public ActionResult addToCartOrderStore()  
        {  
            return View();  
        }  
  
        [HttpPost]  
        public ActionResult addToCartOrderStore(FormCollection sh)  
        {  

I am trying to open below view but below view is not open

addToCartOrderStore.cshtml

@{  
    ViewBag.Title = "addToCartOrderStore";  
}  
  
<h2>AddToCart OrderStore</h2>  
  
  
<script src="~/kendo/js/kendo.all.min.js"></script>  
  
<br />  
<div class="navbar navbar-inverse text-center">  
    <div class="container text-center">  
  
        <div class="navbar-collapse collapse text-center">  
            <ul class="nav navbar-nav text-center">  
                @*<li>@Html.ActionLink("Home", "index")</li>  
                <li> @Html.ActionLink("My Cart", "cartdisplay")</li>  
                <li> @Html.ActionLink("My Orders", "orderdisplay")</li>*@  
  
                <li>@Html.ActionLink("Logout", "Logout")</li>  
            </ul>  
  
        </div>  
    </div>  
</div>  
  
<form id="form"></form>  
  
<script>  
  
  
    $(document).ready(function () {  
  
        var today = new Date();  
  
        var maxDate = today.setDate(today.getDate() + 60);  
  
        $("#form").kendoForm({  
  
            layout: "grid",  
            grid: {  
                cols: 2,  
                gutter: 20  
            },  
            items: [  
                {  
                    type: "group",  
                    label: "Customer Address",  
                    items: [  
                        {  
                            field: "firstname",  
                            label: "First Name:",  
                            validation: { required: true }  
                        },  
                        {  
                            field: "lastname",  
                            label: "Last Name:",  
                            validation: { required: true }  
                        },  

see below error image

https://imgur.com/KvvTGrq

I am trying to open view but give an error the resource cannot be found

need help

Developer technologies ASP.NET Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. AgaveJoe 30,126 Reputation points
    2022-12-10T12:57:03.523+00:00

    The [HttpGet] addToCartOrderStore() action clearly returns a View() (HTML) not a JSON with a redirectToUrl property that the AJAX success handler expects.

    Either fix the action so it returns a JSON with a redirectToUrl property or fix the AJAX success handler.

    0 comments No comments

  2. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2022-12-12T08:10:08.263+00:00

    Hi @Rahul Patil ,
    You can print the response with alert() and you'll find it's an html page. The redirectToUrl function is used to redirect the user to the specified url (syntax: RedirectToUrl("url","target");).
    If you want to redirect to addToCartOrderStore.cshtml, you just need to use the following code:
    269546-image.png

    Or put addToCartOrderStore.cshtml into current page like:

      success: function (response) {  
                         alert(response);  
                         $('#content').html(response);  
                     }  
       
    <div id="content"></div>                         
                       
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.