BeginForm with MVC and JQuery Mobile
I'm trying to get a form to work on a view in a MVC Widget. I added in a @Html.BeginForm and seemed to be working, but has now stopped working. I see that I may need to use the @Html.BeginSitefinityForm, but I can't find what namespace it is from.
www.sitefinity.com/.../adding-form-in-widget-changes-where-main-form-tag-closes
This post says to add @using Telerik.Sitefinity.UI.MVC ...but that does not work. Getting this error when I mouse over. 'System.Web.Mvc.HtmlHelper<SitefinityWebApp.Mvc.Models.LoginModel>' does not contain a definition for 'BeginSitefinityForm' and no extension method 'BeginSitefinityForm' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<SitefinityWebApp.Mvc.Models.LoginModel>' could be found (are you missing a using directive or an assembly reference?)
So, what is happening now is that I hit the home page, click on the login page, type anything into the fields and hit submit on the form and it refreshes and shows the home page, so seems to be refreshing the parent page... Code I have now is below. Any ideas?
@using Telerik.Sitefinity.UI.MVC
@model SitefinityWebApp.Mvc.Models.LoginModel
@
ViewBag.Title = Model.Header;
Layout = "~/MVC/Views/Shared/_Layout.cshtml";
@using (@Html.BeginForm("Login", "Login", null, FormMethod.Post))
/*@using (@Html.BeginSitefinityForm())*/
@Html.AntiForgeryToken();
@Html.ValidationSummary(true, "Login failed. Check your login details.");
<div>
<fieldset>
<legend>Login</legend>
<div class="editor-label">
@Html.LabelFor(u => u.UserName)
</div>
<div class="editor-field">
@Html.TextBoxFor(u => u.UserName)
@Html.ValidationMessageFor(u => u.UserName)
</div>
<div class="editor-label">
@Html.LabelFor(u => u.Password)
</div>
<div class="editor-field">
@Html.PasswordFor(u => u.Password)
@Html.ValidationMessageFor(u => u.Password)
</div>
<div class="editor-label">
@Html.CheckBoxFor(u => u.RememberMe)
@Html.LabelFor(u => u.RememberMe)
</div>
<input type="submit" value="Log In" />
</fieldset>
</div>
So the question here is should I be using the @Html.BeginForm or the @Html.BeginSitefinityForm? I think I am using Hybred mode as I have a cutom WebForms Masterpage behind the MVC widgets, so that would mean that I need to be using @Html.BeginSitefinityForm but then what is the correct namespace to add so that it does not error?
New day and new look at this and have got it working. Two things I needed to fix.
1) I was missing the ';' at the end of the using statement and that is why it could not find BeginFormSitefinity
2) Turns out that the Javascript looks for a form with the id 'aspnetForm' so, need to make sure that is the id of the form in the master page.
Code I have that is working is below.
View -
@using Telerik.Sitefinity.UI.MVC;
@model SitefinityWebApp.Mvc.Models.LoginModel
@
ViewBag.Title = Model.Header;
Layout = "~/MVC/Views/Shared/_Layout.cshtml";
@using (Html.BeginFormSitefinity("Login", "Login", null, FormMethod.Post))
@Html.AntiForgeryToken();
@Html.ValidationSummary(true, "Login failed. Check your login details.");
<div>
<fieldset>
<legend>Login</legend>
<div class="editor-label">
@Html.LabelFor(u => u.UserName)
</div>
<div class="editor-field">
@Html.TextBoxFor(u => u.UserName)
@Html.ValidationMessageFor(u => u.UserName)
</div>
<div class="editor-label">
@Html.LabelFor(u => u.Password)
</div>
<div class="editor-field">
@Html.PasswordFor(u => u.Password)
@Html.ValidationMessageFor(u => u.Password)
</div>
<div class="editor-label">
@Html.CheckBoxFor(u => u.RememberMe)
@Html.LabelFor(u => u.RememberMe)
</div>
<input type="submit" value="Log In" />
</fieldset>
</div>
masterpage -
<%@ Master Language="C#" %>
<!DOCTYPE html>
<html lang="en">
<head runat="server">
<meta charset="utf-8" />
<title></title>
<meta name="viewport" content="width=device-width" />
<asp:PlaceHolder runat="server">
<%: System.Web.Optimization.Styles.Render("~/Content/jquerymobile/css", "~/Content/Mobile/css") %>
<%: System.Web.Optimization.Scripts.Render("~/bundles/modernizr", "~/bundles/jquery", "~/bundles/jqueryui", "~/bundles/jquerymobile") %>
</asp:PlaceHolder>
</head>
<body>
<form runat="server" id="aspnetForm">
<asp:ScriptManager runat="server" />
<asp:contentplaceholder id="MainContent" runat="server" />
</form>
</body>
</html>