简体   繁体   中英

How can I return an ActionResult?

I have an ActionResult that returns a View with a grid that show notes from a database. On the same page there is a button to call CreateNote, which returns a PartialView where I can add new notes. This all works, but after adding the new note I want the view to go back to the TabNotes showing the grid. I tried using

return Redirect(HttpContext.Request.UrlReferrer.AbsoluteUri);

but this goes to the wrong page. So instead I want to return the TabNotes ActionResult. Is this possible?

  public ActionResult CreateNote(
        [ModelBinder(typeof(Models.JsonModelBinder))]
        NoteModel Model, string cmd, long? itemId, string modelEntity)
    {

        if (cmd == "Save")
        {
            Model.meta.message = "Note saved";
            //standard user = 1, needs to be changed to variable
            test.Database.User User = UserRepository.GetUser(1);
            Entity entity = NotesRepository.GetEntity("Phrase");
            NotesRepository.StoreNote(Model.subject, Model.text, User, entity, itemId);
            return Redirect(HttpContext.Request.UrlReferrer.AbsoluteUri);
        }
        Model.meta.modelname = "CreateNote";
        Model.meta.JsViewModelType = "EditNoteModel";
        Model.meta.PostAction = Url.Action("CreateNote", new { cmd = "Save", itemId = itemId});


        return PartialView("CreateNotePartial",Model);

        }

'

    public ActionResult TabNotes([ModelBinder(typeof(Models.JsonModelBinder))]
        TabNotesModel Model, string cmd)
    {
        Entity entity = NotesRepository.GetEntity(Model.meta.entity);
        if (Model.meta.id.HasValue)
        {
            Model.meta.modelname = "TN" + Model.meta.entity + Model.meta.id.Value.ToString();

            Dictionary<string, object> defaultValues = new Dictionary<string, object>();
            defaultValues.Add("Entity", entity.EntityId);
            defaultValues.Add("ItemId", Model.meta.id.Value);
            Entity noteEntity = NotesRepository.GetEntity("Note");
            var grid = UI.GetEntityFlexiGrid(noteEntity, true, true, true, true, defaultValues);
            grid.buttons.Clear();
            grid.title = "";
            Model.Grid = grid;

            Model.Grid.url = Url.Action("TabNoteData", new { id = Model.meta.entity, itemId = Model.meta.id.Value});
        }


       return View("TabNotes", Model);
    }

您应该重定向到该操作:

return RedirectToAction("TabNotes");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM