AI OnAI Off
Would be interested to hear if anyone has an actual solution to this but I have settled on filtering out the extra posts by settings a flag in TempData using these extensions:
public static class ControllerExtensions { private static string GetRunFlagKey(ContentData block, string key) { return "RunFlag" + (block as IContent).ContentLink + key; } public static bool GetRunFlag(this Controller controller, ContentData currentContent, string key) { var b = controller.TempData[GetRunFlagKey(currentContent, key)] as bool?; return b.HasValue; } public static void SetRunFlag(this Controller controller, ContentData currentContent, string key) { controller.TempData.Add(GetRunFlagKey(currentContent, key), true); } }
In the controller's Post function I simply have to check if the post has been called already:
[HttpPost] public ActionResult Index(myModel model, string myValue) { if (!this.GetRunFlag(model.CurrentBlock, myValue)) { this.SetRunFlag(model.CurrentBlock, myValue); ....
I have created a completely standard block that submits a form. When the same block is added to the page twice and one of the forms are submitted, the block controller's Post function also gets called twice?
In the block's view:
And in the block's controller:
Since it is the same block, the viewmodel is not unique so I have no way of filtering out the 2nd Post.
Has anyone else had to deal with this?
Thanks
Simon