0

我正在研究 MVC3,我必须从前端将用户添加到 DB。我正在使用 formcollection。我在 formtag 中使用以下按钮,

     <td> <input type="submit" class="btn" name="adduser" id="btnAdd" value="Add/Edit User" /></td> 
    <td> <input type="submit" class="btn" name="cancel" id="btnCancel" value="Cancel" /></td>

以下是我的控制器方法,

       public ActionResult TravelReadyAdminAccess(FormCollection Collection, string adduser, string cancel)
    {
        TravelReadyAdminBLL objTravelReadyAdminBLL = new TravelReadyAdminBLL();
        try
        {
            int intLoggedinUserId = 0;
            int intMappedUserId = 0;
            intLoggedinUserId = Convert.ToInt32(Collection["loggedinuser"]);
            intMappedUserId = Convert.ToInt32(Collection["mappeduser"]);
            var button = adduser ?? cancel;
            if (button == "Add/Edit User")
            {
                objTravelReadyAdminBLL.TravelReadyAddUser(intLoggedinUserId, intMappedUserId);
                ViewData["EditUser"] = "User Added Sucessfully";
            }
            else if (button == "Cancel")
            {
                return RedirectToAction("TravelReadyAdminAccess");
            }
            return RedirectToAction("TravelReadyAdminAccess");
        }
        catch (Exception ex)
        {
            ILogManager LogManager = new LogManager();
            var frame = new StackFrame(0);
            LogManager.CallLogging(frame, ex.Message, ex.StackTrace);
            return RedirectToAction("Error", "Common");
        }
    }

我想在用户添加时获得成功消息。我需要在控制器方法中返回什么?

4

1 回答 1

0

You can use viewbag in your action method and pass bool value to it. Say for e.g. true for success and false in case of failure and access this viewbag in your view.

于 2013-11-29T05:49:13.973 回答