I have created an SharePoint MVC provider hosted App Part. In my app part I have a form. This form has 2 actions. One is the httpget action and the other is the httppost action. It looks like the httppost action is fired initial. What is going wrong?
This is my reference from the app part to the mvc controller:
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <ClientWebPart Name="AanmakenPeriode" Title="Periode Aanmaken" Description="Het formulier om een periode aan te kunnen maken."> <!-- Content element identifies the location of the page that will render inside the client web part Properties are referenced on the query string using the pattern _propertyName_ Example: Src="~appWebUrl/Pages/ClientWebPart1.aspx?Property1=_property1_" --> <Content Type="html" Src="~remoteAppUrl/CreatePeriode?{StandardTokens}" /> <!-- Define properties in the Properties element. Remember to put Property Name on the Src attribute of the Content element above. --> <Properties> </Properties> </ClientWebPart> </Elements>
These are my actions in my controller:
[HttpGet] public ActionResult Index() { return View(); } [HttpPost] [SharePointContextFilter] public ActionResult Index(PeriodeModel model) { if (ModelState.IsValid) { var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); using (var clientContext = spContext.CreateUserClientContextForSPHost()) { if (clientContext != null) { // some logic to add a new list item, subsite etc. } } } }