Thursday, February 7, 2019

MVC BeginForm with querystring

For a provider hosted app in SharePoint any request to the server must preserve standard SharePoint tockens in query string. I have found a blog that explains how to achieve similar functionality in plain MVC
https://www.danylkoweb.com/Blog/quick-tip-querystrings-with-aspnet-mvc-beginform-FO

In practise, instead of adding another BeginFormQueryString extension to Html object I only copied the extension method on query string

public static RouteValueDictionary ToRouteValueDictionary(this NameValueCollection collection)
        {
            var routeValues = new RouteValueDictionary();
            foreach (string key in collection)
            {
                routeValues[key] = collection[key];
            }
            return routeValues;

        }

And then added the routevalues to OOB BeginForm method like so:



@using (@Html.BeginForm("myAction", "myController", Request.QueryString.ToRouteValueDictionary(), FormMethod.Post))
{

No comments:

Regex obfuscate email

 Use this code in C# to obfuscate email using regex // Online C# Editor for free // Write, Edit and Run your C# code using C# Online Compile...