Solved

asp.net, mvc 3

Posted on 2013-11-06
4
522 Views
Last Modified: 2013-11-22
I have below codes in Controller and the model(ClassLibrary.Bail) is not in the local Model folder. It is in reference under References folder.

My issue is: it is always returned "False" and I don't know how to fix it.

Look like if the Model is inside of the Model folder, it is working.

[HttpPost]
        public ActionResult Index(ClassLibrary.Bail model)
        {
            if (ModelState.IsValid)
            {
                #region steps
                int result = ServRef.AddBailBondQuote(model);
               
                #endregion
                Response.Write(result);
            }
            else
            {
                Response.Write("Something Wrong");
            }
            return View();
        }
0
Comment
Question by:solution1368
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39630359
If you are saying that ModelState.IsValid is always false, then you should be able to find out what the errors are with the ModelState.Errors Property
0
 
LVL 25

Expert Comment

by:apeter
ID: 39631257
ModelState.IsValid will be false if the validation for the Model fails:

You have DataAnnotation which failed the incoming model.
You added custom validations.
Make sure there are no null entries in the model for non null properties

Check the ModelState.Errors for what is the reason causing this by,

var errorsMsgs = ModelState.Values.SelectMany(v => v.Errors);

Open in new window

0
 

Author Comment

by:solution1368
ID: 39652619
System.Linq.Enumerable+d__14`2[System.Web.Mvc.ModelState,System.Web.Mvc.ModelError]

Above error is generated.  Remember the model i have is not in the mvc app.
It is reference from other project that we have been using.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 39652723
You need to get the error messages, not the errors.  That would be something like this:

var errorsMsgs = ModelState.Values
  .SelectMany(v => v.Errors)
  .Select(x => x.ErrorMessage)
  .ToList();

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
c# deserialize JSON from web service using JsonConvert 9 62
Data Analysis 7 59
Make borderless form movable by user 2 27
Need a quick overview of Selenium testing 2 36
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question