1

I have to work with queries like: Controller/Action?query ={"action":"test","id":"13037313353","pin":"452312"} by GET.

My ViewModel:

 public class ValidatePinViewModel
    {
        public ActionType action { get; set; }

        public int Id { get; set; }

        public int Pin { get; set; }
    }

Controller

 public JsonResult ValidateVisit(CommonViewModel model)
        {
            //model is null          

            return Json(new InvalidPin());
        }

Now I got null for my view. How I can get the correct model

2 Answers 2

1

As there is very little supportive information on this question, I'm going to take a shot and say that you're not POSTING to an action. e.g.

[HttpPost] // <-- Make sure you define your POST action
public JsonResult ValidateVisit(CommonViewModel model)
{
   ...
}

A GET, as you speficy in your tags, is not going to post a model. Unless you are specifically denoting it both in where you define your form element as well as on the action itself, it will be null.

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

3 Comments

Yep, I am working with another service, which send this type of query by GET.
Then the other service is wrong. If the other service is posting data, it should use POST.
I know. I can`t change it. I can only use it.
1

I could add a string to get object.

Something like:

 public JsonResult ValidateVisit(string query)
 {
    ValidatePinViewModel model = Json.Deserialize<ValidatePinViewModel>(query);       
    return Json(new InvalidPin());
 }

Comments

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.