Solved

asp.net, mvc 3

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

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 …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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