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:

SSL Error - The connection for this site is not secure

 After cloning a git repo of dot net framework website and trying to run it all I could see was this error Turns out the fix was to simply e...