0

I want to call this yellow colored Controller function with ajax (Image of my project). and this is my JavaScript function in View:

function notificationDivPressed(element,x,user,numberOfUsers) {  

    jQuery(document).ready(function ($) {

        $.ajax({
            url: 'MvcApplication3/Controllers/NotificationController/ChangeReadStatus',
            type: "POST",
            cache: false,
            data: { arg: x },
            success: function (data) {

                }
            }
        });
    });   
}

when I write url like that (url: 'MvcApplication3/Controllers/NotificationController/ChangeReadStatus') it doesn't work. What should I change to get a desired result?

2 Answers 2

2

As you saw your URL is wrong (because you're just using a mix of project paths and class name instead of proper URL that MVC framework will rewrite and route to right methods).

Change it with:

url: '@Url.Action("ChangeReadStatus", "Notification")'
Sign up to request clarification or add additional context in comments.

Comments

0

Change to

url: '/Notification/ChangeReadStatus'

2 Comments

Please do him a favor and don't hard-code action method URLs!
Adriano, got it. Thought it might be easier for him to understand for a beginner. But you are right.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.