I have been struggling from last 2 days to find clear and exemplified documentation on how to build modules using MVC framework for DOTNETNUKE CMS.
It is very unfortunate for a CMS of that size to first advertise app developers that they support MVC, and then have next to negligible information on how to build say a very simple form to begin with.
This is what I have achieved by now. I am trying to build a basic contact us form:
Set up Controller Actions
// GET: FormEntry Index .. [ModuleAction(ControlKey = "Add", TitleKey = "AddItem")] public ActionResult Index() { return View(); } [HttpPost] // POST: [ActionName("FormEntry")] public string Post(FormEntry formEntry) { try { if (ModelState.IsValid) { FormEntryManager.Instance.CreateItem(formEntry); } return "success"; } catch(Exception ex) { return "error"; } }
Set up a View.
<div id="Item-@Dnn.ModuleContext.ModuleId"> <form id="formcontactus"> @*@Html.ValidationSummary(true)*@ <fieldset> <div class="dnnFormItem"> <div><label for="itemName">@Dnn.LocalizeString("lblName")</label></div> @Html.TextBoxFor(m => m.VisitorName) @Html.ValidationMessageFor(m => m.VisitorName, @Dnn.LocalizeString("VisitorNameRequired")) </div> <div class="dnnFormItem"> <div><label for="itemDescription">@Dnn.LocalizeString("lblVisitorEmail")</label></div> @Html.TextBoxFor(m => m.VisitorEmail) @Html.ValidationMessageFor(m => m.VisitorEmail, @Dnn.LocalizeString("VisitorEmailRequired")) </div> <div class="dnnFormItem"> <div><label for="itemDescription">@Dnn.LocalizeString("lblPhone")</label></div> @Html.TextBoxFor(m => m.VisitorPhone) </div> <div class="dnnFormItem"> <div><label for="itemDescription">@Dnn.LocalizeString("lblMessage")</label></div> @Html.TextAreaFor(m => m.VisitorMessage) @Html.ValidationMessageFor(m => m.VisitorMessage, @Dnn.LocalizeString("VisitorMessageRequired")) </div> @Html.HiddenFor(m => m.ModuleId) </fieldset> <button id="btnSumbit" type="button" class="dnnPrimaryAction">@Dnn.LocalizeString("Submit")</button> <a id="cancelEdit" href="#" class="dnnSecondaryAction">@Dnn.LocalizeString("Cancel")</a> </form> </div>
My index view does get rendered successfully, and I can see my form. Issue is in understanding the way in which I post this data to the MVC Post method. Also my data annotations for validations on my modal class does not work on client side.
I tried posting through jQuery Ajax on the Post method, but that throws an internal error.
Looking forward to hear from DNN community.