Solved

asp.net, mvc 3

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Chat Room 1 30
File Upload Control on a ASP.NET Overlay Page 1 26
Loop through Multiple Processes Async 2 17
Entity Framework 3 11
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now