Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

C#
[AcceptVerbs(HttpVerbs.Post)]
[GridAction]
public ActionResult _InsertIdConfiguration(IdConfigurationViewModel idsView)
{
    IdConfigDTO _idConfig = new IdConfigDTO();
    RepositoryMethodInvoker _mi = new RepositoryMethodInvoker();
    var _context = Request.GetContextData();
    SiteDTO _site;

    try
    {
        if (ModelState.IsValid)
        {
            model = new MasterDataModel(_context);
            if (idsView.SelectedSiteIIds != null)
            {
                _idConfig.Sites = new List<sitedto>();
                foreach (var _iid in idsView.SelectedSiteIIds)
                {
                    _site = new SiteDTO();
                    _site.SiteIId = _iid;
                    _idConfig.Sites.Add(_site);
                }
            }
            _idConfig.Type = idsView.Type;
            _idConfig.Increment = idsView.Increment;
            _idConfig.MinimumLength = idsView.MinimumLength;
            _idConfig.Prefix = idsView.Prefix;
            _idConfig.Suffix = idsView.Suffix;
            _idConfig.IdsIId = idsView.IdsIId;
            Func<decimal> _method = new Func<decimal>(() => model.UpdateIdConfiguration(_idConfig));
            _mi.ExecuteFunction(_method);
        }
        else
        {

        }
    }

    catch (FaultException ex)
    {
        return AppHelper.GetGridErrorResult(ex);
    }
    return _SelectIdConfiguration();
}

this is the coding am tried in else block how i can show error message to customer id modelstate is invalid..


Please help to solve this...
Posted
Updated 30-Jul-12 18:06pm
v2

1 solution

The framework will add the error messages defined in the model with DataAnnotation, but you can add custom validation errors:
C#
ModelState.AddModelError("fieldname", "error message");

In the view you can add
C#
Html.ValidationMessage("fieldname")
or ValidationMessageFor to the fields. Or use ValidationSummary somewhere near the form.
You can also use ViewBag to pass data between controller and view.

Be aware that if you use model generated from database, you need to use partial classes to add DataAnnotation.

Update:
You forget to share an important information with us: this action is called in an ajax backtalk. See this thread: http://www.telerik.com/community/forums/aspnet-mvc/grid/how-to-return-error-information-to-grid-in-ajax-editing-mode.aspx[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900