Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
[HttpPost]
[MenuAuthorize("82B5690B-BEA7-40EC-9643-E4E37431833B")]
public ActionResult RoundOff(RoundoffSetting model)
{
    try
    {
        var item = (from a in wallet.RoundoffSettings where a.CompanyId == CompanyId select a).FirstOrDefault();

        if (item == null)
        {
            item = new RoundoffSetting();
            item.CompanyId = CompanyId ?? 0;
            item.CreatedBy = User.Identity.Name;
            item.CreatedDate = DateTime.Now;

            wallet.RoundoffSettings.Add(item);
        }
        else
        {
            item.ModifiedBy = User.Identity.Name;
            item.ModifiedDate = DateTime.Now;
        }

        item.RoundingType = model.RoundingType;
        item.RoudingValue = model.RoudingValue;

        wallet.SaveChanges();

        return Success(M("RoundOffSaveSucess"));
    }
    catch (Exception e)
    {
        log.Error("Failed to save RoundOff", e);
        return Error();
    }
}


What I have tried:

I have given code for saving Action...in this ,After save the data some successfull message has to display .. in this code i had wrote return success in that place i passed one message you seen.that message only display after am saving my form ....please help me if anyone know this please share the code please help me
Posted
Updated 11-Apr-16 20:18pm
Comments
F-ES Sitecore 6-Apr-16 7:03am    
What is "M"? Or "Success"? Is this action being navigated to? Or called from ajax?
Member 11183217 6-Apr-16 8:00am    
M is an Resource Id. all hardcode Names i send it to Resources... ya tat part only am asking in that success method i dont need, instead of that only am asking idea from ur side sir..in that return i want to get a save messages by using some other way


please help me
F-ES Sitecore 6-Apr-16 10:34am    
If we don't understand how this action is called and what it returns, no-one can tell you how you can use it to show a message on the screen.

1 solution

Hello,

First of all in the controller action, using the context or Data layer inside action method is a bad approach.

Next is the Success method as rightly mentioned in the Comments section, why is it required, when you can store the Success message in any model property, if you are returning a view from the Action, which ideally you should. if you return a view, you can always create a separate Model property named ValidationMessage, or use ViewBag, tempdata anything of that sort.

If you are using any ajax call to call this Post method, then that would be simple to make a boolean return from the method and based on the response manipulate in the ajax success part.

Thanks
 
Share this answer
 

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