Ajax request using Asp . net core

Asked

Viewed 18 times

0

I’m having trouble with this request... It’s returning 'not been' on the console. The getValue() method is in the Controller/Homecontroller.Cs

/* JS */

 var obj = {
        emails: 'teste'
    }

    var json = JSON.stringify(obj)

    $.ajax({
        cache: false,
        type: 'POST',
        url: '/Home/getValue',
        data: json,
        contentType: 'application/json',
        success: (e) => {
            console.log('foi')
        },
        error: (e) => {
            console.log('nao foi')
        }
    })

/* getValue */

[HttpPost]
public ActionResult getValue(string dados) {
 
return View();
}

I also created a class in Models>Testemodel.Cs

public class TestModel {
   public string teste {get; set;}
}

Could you help me? I think the problem might be at the url of ajax... Console error message: POST https://localhost:44355/Home/getValue 500 jquery.min.js:2

  • Your route is /Home whether or not with a capital H?

  • I put with a capital H, but I don’t know if the default url to access the Homecontroller is with a capital H.

  • @Rennanalves remove the return View(); of its method in the Controller. You can only return a View() that exists.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.