0

I send ajax request using this code:

$.ajax({
  url: "/Home/ShowStadium",
  contentType: "application/json; charset=utf-8",
  dataType: "text",
  type: "POST",
  data: Club,
  success: function (data) {
        $(".right-content").html(data);
          },
  error: function (xhr, textStatus) {
         alert([xhr.status, textStatus]);
        }

  });

In HomeController i have this function:

[HttpPost]
        public ActionResult ShowStadium(){

            if (Request.Form["Club"] == "Some text to compare")
            {
                return Content("First variant");
            }
            else
            {
                return Content("Second variant");
            }

        }

But i can't get data sent by ajax to compare it. Request.Form["Club"] - not working!

1
  • What is Club in data: Club,? Your should add a parameter to you method public ActionResult ShowStadium(string Club) {... Commented Oct 30, 2014 at 7:46

1 Answer 1

2

Use as

$.ajax({
  url: "/Home/ShowStadium",
  contentType: "application/json; charset=utf-8",
  dataType: "text",
  type: "POST",
  data: {club:Club},
  success: function (data) {
        $(".right-content").html(data);
          },
  error: function (xhr, textStatus) {
         alert([xhr.status, textStatus]);
        }

  });

In HomeController i have this function:

[HttpPost]
        public ActionResult ShowStadium(string club){

            if (club == "Some text to compare")
            {
                return Content("First variant");
            }
            else
            {
                return Content("Second variant");
            }

        }
Sign up to request clarification or add additional context in comments.

4 Comments

I tried this way , but I getting "error 500" from ajax whit this code.
try after removing datatype
try removing content-type and set datatype:json
Issue is to remove content-type end retain dataType: text

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.