在btn点击上记录成功保存 [英] Record suceessfully saved on btn click

查看:70
本文介绍了在btn点击上记录成功保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在添加模型validadation正确记录和btn点击然后我需要msg记录成功保存...在mvc 3层。



我尝试过:



// BAL(LOGIC PAGE)

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)

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();    
    }
}

推荐答案

您创建一个模型;



You create a model;

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





更新你的行动以使用模特





Update your action to use the model

[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>
}


这篇关于在btn点击上记录成功保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆