Skip to main content
Notice removed Authoritative reference needed by CommunityBot
Bounty Ended with no winning answer by CommunityBot
Notice added Authoritative reference needed by Ola
Bounty Started worth 50 reputation by Ola
added 897 characters in body
Source Link
Ola
  • 4.4k
  • 27
  • 135
  • 233

This is my form in the view:

@model MyNameSpace.Models.PeriodeModel @{ Layout = null; } @if(TempData["notice"] != null) { <h2>@TempData["notice"]</h2> } @using (Html.BeginForm()) { @Html.Label("Omschrijving") <br /> @Html.TextBoxFor(m => m.PeriodeOmschrijving) <br /> @Html.ValidationMessageFor(m => m.PeriodeOmschrijving) <br /> <br /> @Html.Label("Vanaf") <br /> @Html.TextBoxFor(m => m.PeriodeVanaf) <br /> @Html.ValidationMessageFor(m => m.PeriodeVanaf) <br /> <br /> @Html.Label("T/M") <br /> @Html.TextBoxFor(m => m.PeriodeTM) <br /> @Html.ValidationMessageFor(m => m.PeriodeTM) <br /> <br /> <input type="submit" value="Aanmaken" /> } 

This is my form in the view:

@model MyNameSpace.Models.PeriodeModel @{ Layout = null; } @if(TempData["notice"] != null) { <h2>@TempData["notice"]</h2> } @using (Html.BeginForm()) { @Html.Label("Omschrijving") <br /> @Html.TextBoxFor(m => m.PeriodeOmschrijving) <br /> @Html.ValidationMessageFor(m => m.PeriodeOmschrijving) <br /> <br /> @Html.Label("Vanaf") <br /> @Html.TextBoxFor(m => m.PeriodeVanaf) <br /> @Html.ValidationMessageFor(m => m.PeriodeVanaf) <br /> <br /> @Html.Label("T/M") <br /> @Html.TextBoxFor(m => m.PeriodeTM) <br /> @Html.ValidationMessageFor(m => m.PeriodeTM) <br /> <br /> <input type="submit" value="Aanmaken" /> } 
Source Link
Ola
  • 4.4k
  • 27
  • 135
  • 233

Why is my form validation fired initial in my mvc app part?

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. } } } }