Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jan A 63 posts 268 karma points
    Jun 29, 2021 @ 12:03
    Jan A
    0

    Clear paramters on POST to surfacecontroller

    I have an surfaceController that generates a form with header - rows

    class Header 
    {
       public int Id {get;set;}
       public IList<Row> Rows {get;set;}
    }
    
    class Row
    {
       public int Id { get; set; }
       public string Name { get; set; }
       public bool Delete {get;set;}
    }
    

    In the get function I will grab these rows from the db.

    On Post I will check some things, and if it's not correct I return CurrentUmbracoPage()

    return CurrentUmbracoPage();
    

    If the Delete is set on Row I will delete that row before return CurrentUmbracoPage()

    The CurrentUmbracoPage will regenerate the model as exprected, but the problem is that the form parameters is still in the call and will overwrite any changes I load in the get So if the first call was: headerModel.Rows[0].Name = "Row 1" headerModel.Rows[1].Name = "Row 2" headerModel.Rows[2].Name = "Row 3"

    After the delete of "Row 2" the ViewModel has 2 rows (1 and 3) but when I generate the form the value for "Row 3" will be the posted "Row 2" value.

    I understand why the modelstate is overwritten since you almost always want to display user input. But in my case I would like to ignore this and display the new values. In a "normal" application I guess I would just call a return Redirect("Action") instead, but since this is a [ChildActionOnly] called that is not possible.

    Is there a way to resolve this so either the formstate is not changed or return the CurrentUmbracoNode without the Post parameters?

  • Jan A 63 posts 268 karma points
    Jun 29, 2021 @ 15:26
    Jan A
    0

    As I wrote this I figured it out. Just redirect to CurrentPage.Id instead

    return RedirectToUmbracoPage(CurrentPage.Id)
    
Please Sign in or register to post replies

Write your reply to:

Draft