/// <summary> /// Generates the Form preamble /// </summary> /// <param name="ajax"></param> /// <param name="controllerName"></param> /// <param name="routeValues"></param> /// <param name="ajaxOptions"></param> /// <param name="actionType"></param> /// <returns></returns> public static MvcForm BeginResourceForm(this AjaxHelper ajax, string controllerName, object routeValues, AjaxOptions ajaxOptions, ActionType actionType) { switch (actionType) { case ActionType.GetUpdateForm: return(ajax.BeginRouteForm(controllerName + "-editForm", routeValues, ajaxOptions)); case ActionType.GetCreateForm: return(ajax.BeginRouteForm(controllerName + "-createForm", ajaxOptions)); case ActionType.Retrieve: case ActionType.Delete: case ActionType.Update: // can we use ajaxOptions to either add the header? MvcForm form = ajax.BeginRouteForm(controllerName, routeValues, ajaxOptions); return(form); case ActionType.Create: return(ajax.BeginRouteForm(controllerName + "-create", ajaxOptions)); case ActionType.Index: return(ajax.BeginRouteForm(controllerName + "-index", ajaxOptions)); default: throw new ArgumentOutOfRangeException("actionType"); } }
public AjaxContactForm(AjaxHelper ajaxHelper, PagePayload page, AjaxOptions ajaxOptions, object formAttributes = null) { _helper = ajaxHelper; if (page == null) { page = PagePayload.GetCurrentContent(); } if (ajaxOptions == null) { ajaxOptions = new AjaxOptions(); ajaxOptions.InsertionMode = InsertionMode.Replace; } if (String.IsNullOrEmpty(ajaxOptions.HttpMethod)) { ajaxOptions.HttpMethod = "POST"; } if (String.IsNullOrEmpty(ajaxOptions.UpdateTargetId)) { ajaxOptions.UpdateTargetId = "frmContact"; } if (String.IsNullOrEmpty(ajaxOptions.OnFailure)) { ajaxOptions.OnFailure = "__OnAjaxRequestFailure"; } string formAction = "Contact.ashx"; //try #3 //RouteValueDictionary dic = new RouteValueDictionary(); //dic.Add("controller", "CmsAjaxForms"); //dic.Add("action", formAction); //if (SecurityData.AdvancedEditMode) { // dic.Add(SiteData.AdvancedEditParameter, true); //} //frm = ajaxHelper.BeginRouteForm("Default", dic, ajaxOptions, formAttributes); //try #2 if (SecurityData.AdvancedEditMode) { frm = ajaxHelper.BeginRouteForm("Default", new { controller = "CmsAjaxForms", action = formAction, carrotedit = true }, ajaxOptions, formAttributes); } else { frm = ajaxHelper.BeginRouteForm("Default", new { controller = "CmsAjaxForms", action = formAction }, ajaxOptions, formAttributes); } /* * //try #1 * string formAction = "Contact.ashx"; * FormRouteValue frv = new FormRouteValue("CmsAjaxForms", formAction); * * if (SecurityData.AdvancedEditMode) { * frv = new FormRouteValue("CmsAjaxForms", formAction, true); * } * * frm = ajaxHelper.BeginRouteForm("Default", frv, ajaxOptions, formAttributes); */ }
public AjaxResetPasswordForm(AjaxHelper ajaxHelper, PagePayload page, AjaxOptions ajaxOptions, object formAttributes = null) { _helper = ajaxHelper; if (page == null) { page = PagePayload.GetCurrentContent(); } if (ajaxOptions == null) { ajaxOptions = new AjaxOptions(); ajaxOptions.InsertionMode = InsertionMode.Replace; } if (String.IsNullOrEmpty(ajaxOptions.HttpMethod)) { ajaxOptions.HttpMethod = "POST"; } if (String.IsNullOrEmpty(ajaxOptions.UpdateTargetId)) { ajaxOptions.UpdateTargetId = "frmResetPassword"; } if (String.IsNullOrEmpty(ajaxOptions.OnFailure)) { ajaxOptions.OnFailure = "__OnAjaxRequestFailure"; } string code = ResetPasswordInfoSettings.CodeUrl; string formAction = "ResetPassword.ashx"; if (SecurityData.AdvancedEditMode) { frm = ajaxHelper.BeginRouteForm("Default", new { controller = "CmsAjaxForms", action = formAction, @code = code, @carrotedit = true }, ajaxOptions, formAttributes); } else { frm = ajaxHelper.BeginRouteForm("Default", new { controller = "CmsAjaxForms", action = formAction, @code = code }, ajaxOptions, formAttributes); } }
public void RouteForm() { // Arrange AjaxHelper ajaxHelper = GetAjaxHelper(); AjaxOptions ajaxOptions = GetEmptyOptions(); StringWriter writer = new StringWriter(); ajaxHelper.ViewContext.Writer = writer; // Act IDisposable form = ajaxHelper.BeginRouteForm("namedroute", ajaxOptions); // Assert Assert.AreEqual(AjaxRouteFormWithNamedRoute, writer.ToString()); }
public void RouteForm() { // Arrange Mock <HttpResponseBase> mockResponse = new Mock <HttpResponseBase>(MockBehavior.Strict); AjaxHelper ajaxHelper = GetAjaxHelper(mockResponse); AjaxOptions ajaxOptions = GetEmptyOptions(); // Arrange expectations mockResponse.Expect(response => response.Write(AjaxRouteFormWithNamedRoute)).Verifiable(); // Act IDisposable form = ajaxHelper.BeginRouteForm("namedroute", ajaxOptions); // Assert mockResponse.Verify(); }
public void RouteFormTypedValues() { // Arrange AjaxHelper ajaxHelper = GetAjaxHelper(); AjaxOptions ajaxOptions = GetEmptyOptions(); RouteValueDictionary values = new RouteValueDictionary(); StringWriter writer = new StringWriter(); ajaxHelper.ViewContext.Writer = writer; // Act IDisposable form = ajaxHelper.BeginRouteForm("namedroute", values, ajaxOptions); // Assert Assert.AreEqual(AjaxRouteFormWithEmptyOptions, writer.ToString()); }
public void RouteFormCanUseNamedRouteWithoutSpecifyingDefaults() { // DevDiv 217072: Non-mvc specific helpers should not give default values for controller and action // Arrange AjaxHelper ajaxHelper = GetAjaxHelper(); ajaxHelper.RouteCollection.MapRoute("MyRouteName", "any/url", new { controller = "Charlie" }); StringWriter writer = new StringWriter(); ajaxHelper.ViewContext.Writer = writer; // Act IDisposable form = ajaxHelper.BeginRouteForm("MyRouteName", new AjaxOptions()); // Assert Assert.AreEqual(AjaxRouteFormWithNamedRouteNoDefaults, writer.ToString()); }
public void RouteFormAnonymousValuesAndAttributes() { // Arrange AjaxHelper ajaxHelper = GetAjaxHelper(); AjaxOptions ajaxOptions = new AjaxOptions { UpdateTargetId = "some-id" }; object htmlAttributes = new { method = "get" }; StringWriter writer = new StringWriter(); ajaxHelper.ViewContext.Writer = writer; // Act IDisposable form = ajaxHelper.BeginRouteForm("namedroute", null, ajaxOptions, htmlAttributes); // Assert Assert.AreEqual(AjaxRouteFormWithHtmlAttributes, writer.ToString()); }
public void RouteFormCanUseNamedRouteWithoutSpecifyingDefaults() { // DevDiv 217072: Non-mvc specific helpers should not give default values for controller and action // Arrange Mock <HttpResponseBase> mockResponse = new Mock <HttpResponseBase>(MockBehavior.Strict); AjaxHelper ajaxHelper = GetAjaxHelper(mockResponse); ajaxHelper.RouteCollection.MapRoute("MyRouteName", "any/url", new { controller = "Charlie" }); // Arrange expectations mockResponse.Expect(response => response.Write(AjaxRouteFormWithNamedRouteNoDefaults)).Verifiable(); // Act IDisposable form = ajaxHelper.BeginRouteForm("MyRouteName", new AjaxOptions()); // Assert mockResponse.Verify(); }
public void RouteFormAnonymousValuesAndAttributes() { // Arrange Mock <HttpResponseBase> mockResponse = new Mock <HttpResponseBase>(MockBehavior.Strict); AjaxHelper ajaxHelper = GetAjaxHelper(mockResponse); AjaxOptions ajaxOptions = new AjaxOptions { UpdateTargetId = "some-id" }; object htmlAttributes = new { method = "get" }; // Arrange expectations mockResponse.Expect(response => response.Write(AjaxRouteFormWithHtmlAttributes)).Verifiable(); // Act IDisposable form = ajaxHelper.BeginRouteForm("namedroute", null, ajaxOptions, htmlAttributes); // Assert mockResponse.Verify(); }
public void RouteFormAnonymousValues() { // Arrange Mock <HttpResponseBase> mockResponse = new Mock <HttpResponseBase>(MockBehavior.Strict); AjaxHelper ajaxHelper = GetAjaxHelper(mockResponse); AjaxOptions ajaxOptions = GetEmptyOptions(); AjaxHelper poes = GetAjaxHelper(); // Arrange expectations string x = ajaxHelper.RouteLink("a", "namedroute", GetEmptyOptions()); string y = poes.RouteLink("a", "namedroute", null, ajaxOptions, new RouteValueDictionary()); mockResponse.Expect(response => response.Write(AjaxRouteFormWithEmptyOptions)).Verifiable(); // Act IDisposable form = ajaxHelper.BeginRouteForm("namedroute", null, ajaxOptions); // Assert mockResponse.Verify(); }
public void RouteFormTypedValuesAndAttributes() { // Arrange AjaxHelper ajaxHelper = GetAjaxHelper(); Dictionary <string, object> htmlAttributes = new Dictionary <string, object> { { "method", "get" } }; AjaxOptions ajaxOptions = new AjaxOptions { UpdateTargetId = "some-id" }; RouteValueDictionary values = new RouteValueDictionary(); StringWriter writer = new StringWriter(); ajaxHelper.ViewContext.Writer = writer; // Act IDisposable form = ajaxHelper.BeginRouteForm("namedroute", values, ajaxOptions, htmlAttributes); // Assert Assert.AreEqual(AjaxRouteFormWithHtmlAttributes, writer.ToString()); }
public void RouteFormTypedValuesAndAttributes() { // Arrange Mock <HttpResponseBase> mockResponse = new Mock <HttpResponseBase>(MockBehavior.Strict); AjaxHelper ajaxHelper = GetAjaxHelper(mockResponse); Dictionary <string, object> htmlAttributes = new Dictionary <string, object> { { "method", "get" } }; AjaxOptions ajaxOptions = new AjaxOptions { UpdateTargetId = "some-id" }; RouteValueDictionary values = new RouteValueDictionary(); // Arrange expectations mockResponse.Expect(response => response.Write(AjaxRouteFormWithHtmlAttributes)).Verifiable(); // Act IDisposable form = ajaxHelper.BeginRouteForm("namedroute", values, ajaxOptions, htmlAttributes); // Assert mockResponse.Verify(); }
public MvcForm BeginRouteForm(string routeName, AjaxOptions ajaxOptions) { return(_helper.BeginRouteForm(routeName, ajaxOptions)); }
public static MvcForm SecureBeginRouteForm(this AjaxHelper ajaxHelper, string routeName, ActionResult result, AjaxOptions ajaxOptions, IDictionary <string, object> htmlAttributes) { return(ajaxHelper.BeginRouteForm(routeName, result.GetRouteValueDictionary(), ajaxOptions, htmlAttributes)); }