Solved

asp.net, mvc 3

Posted on 2013-11-06
4
518 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…

740 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