Click here to Skip to main content
15,910,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i add model validadation now when record properly and btn click then i required msg "record sucessfully saved " ...in mvc 3 tier.

What I have tried:

//BAL (LOGIC PAGE)
C#
public  class logicfile
{
    tbloneEntities db = new tbloneEntities();

    public void insert(mone m)
    {
        onetbl ot = new onetbl();  
        threetbl jd = new threetbl();
        ot.id = m.id;
        ot.name = m.name;
        ot.state = m.state;
        ot.cournt = m.cournt;
        ot.city = m.city;  
        db.onetbls.Add(ot);
        db.SaveChanges();
        jd.comments = m.comments;
        jd.fid = ot.id;
        db.threetbls.Add(jd);
        db.SaveChanges();
    }

    //contoller
    public ActionResult Index()
    {
        return View(); 
    }

    [HttpPost]
    public ActionResult Index(mone m)
    {      
        lc.insert(m);
        return View();    
    }
}
Posted
Updated 1-May-16 0:31am
v2
Comments
George Jonsson 1-May-16 3:55am    
So what is your question?
Jaydeep Shah 3-May-16 2:26am    
my question is that ..when i click btn data goes to database ..but it does not give a message like " record successfully saved "..
i dont no how to do this ...i write insert code in BAL.. and call in controller...
George Jonsson 3-May-16 2:34am    
So your question basically is "How to display the message 'record successfully saved' after inserting data successfully into the database?"
Jaydeep Shah 3-May-16 3:27am    
yes..yes now you got what i mean ..!! can you tell me ..:)
George Jonsson 3-May-16 4:10am    
What about solution 1?

1 solution

You create a model;

C#
public class MyModel
{
    public bool Saved { get; set; }
}


Update your action to use the model

C#
[HttpPost]
public ActionResult Index(mone m)
{
    lc.insert(m);
    MyModel model = new MyModel();
    model.Saved = true;
    return View(model);
}


Amend your view to use the model

@model MyModel

@if (Model != null && Model.Saved)
{
    <div>Data saved</div>
}
 
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