Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8901057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:15:18+00:00 2026-06-15T01:15:18+00:00

I have created a following model public class myModel { public int ID; public

  • 0

I have created a following model

public class myModel
{
    public int ID;
    public string Name;
    public int[] days;
}

Then I created an action in a controller

[HttpPost]
public ActionResult myCtrlAction(myModel thisModel)
{
   if (ModelState.IsValid)
        {
            return Json(thisModel);
        }
        else
        {
            string errorMessage = "<div class=\"validation-summary-errors\">"
              + "The following errors occurred:<ul>";
            foreach (var key in ModelState.Keys)
            {
                var error = ModelState[key].Errors.FirstOrDefault();
                if (error != null)
                {
                    errorMessage += "<li class=\"field-validation-error\">"
                     + error.ErrorMessage + "</li>";
                }
            }
            errorMessage += "</ul>";
            return Json(new myModel { Name = errorMessage });  //just for now
        } 
   }

In my javascript I send the data using jQuery.post() as

$("#myBtn").click(function () {
var mydata = {
          ID: $("#inputID").val(),
          Name: $("#inputName").val(),
          Days: $("#selectDays").select2("val")
       }
    var url = 'myController/myCtrlAction';  //definitly it was writtern as @Url.Action
    $.post(url, mydata, function(data) { alert(data); //which shows [object object] 
                     }, 'json');
 });

Now On request when I debug in Chrome I saw in headers as

Form Data
ID: 5
Name: SomeName
Days[]: 6
Days[]: 5

In Response I got json format of my model as

{ID: “0”, Name: “null”, Days: “null”} it means my model state is valid but why its not having the values?

Any body has any idea. what I did wrong or do I miss something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:15:19+00:00Added an answer on June 15, 2026 at 1:15 am

    I think your model’s data is not set thus you get null values on Chrome.

    If your javascript does not have a typo (and that you only made a typo when creating the question, then try this in your method myCtrlAction;

    First try create getters and setters for your fields in myModel. Then;

    replace;

     errorMessage += "</ul>";
    
     return Json(new myModel { Name = errorMessage });  //just for now
    

    with this;

     myModel myMODTest= new myModel();
     myMODTest.setID(1111);
     myMODTest.setName("testName");
     myMODTest.setDays({1,2,3});
     return Json(myMODTest);  //just for now
    

    See if you get on your browser the following;

    {ID: "1111", Name: "testName", Days: "{1,2,3}"}

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following model: public class Product { public int Id { get;
i have this model on mvc: public class User { public string Name {
I have created the following class class Contact def initialize(id, name, phone) @id =
I have created the following custom ValidationAttribute: public class DateRangeAttribute : ValidationAttribute, IClientValidatable {
I’m developing MVC application and I have following classes in my model: public class
I'm writing an MVC2 app using DataAnnotations. I have a following Model: public class
I have the following ViewModel: public class TransportationUnit : ViewModelBase { private string _TypeOfFuel;
I've created the following view model: public class PropertyViewModel { public PropertyViewModel(Property property, IList<PropertyImage>
I have a Model created with a table called Customers. It contains the following
I have a method with the signature public void setFoo(int newFoo) in a model

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.