Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
My controller is not getting model in MVC Umbraco,Its giving error in Modelname.
Adding my code:
public class ContactFormSurfaceController : SurfaceController { public ActionResult RenderContactForm() {
return PartialView("ContactForm", new ContactFormViewModel()); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult HandleContactForm(ContactFormViewModel model) { if (!ModelState.IsValid) { return CurrentUmbracoPage(); } MailMessage email = new MailMessage(model.Email, "[email protected]"); email.Subject = "Contact Form Request"; email.Body = model.Message; try { SmtpClient smtp = new SmtpClient(); smtp.Send(email); } catch (Exception ex) { throw ex; } TempData["IsSuccessful"] = true; return RedirectToCurrentUmbracoPage(); }
}
Hi
Could you add your Partial View Code for ContactForm? I assume the Partial View is rendering your Contact Form Ok? from the below code?
public ActionResult RenderContactForm() { return PartialView("ContactForm", new ContactFormViewModel()); }
Just be sure when you Render the ContactFrom on your View you are calling:
@Html.Action("RenderContactForm", "ContactFormSurface")
And then in your Partial View you should have this at the top:
@model ContactFormViewModel
To Post the forms contents you need something like this in the partial view:
@using (Html.BeginUmbracoForm<ContactFormSurfaceController>("HandleContactForm", FormMethod.Post, new { @class = "form-horizontal" })) { //for example @Html.TextBoxFor(model => model.Name, new { @class = "form-control", @placeholder = "*Name" }) }
Thanks for your reply,I have added partial view and getting error in calling controller contactformsurfacecontroller.
Here is my code:
@model ContactFormViewModel @Html.Action("RenderContactForm", "ContactFormSurface") @using Umbraco.Web
@using (Html.BeginUmbracoForm<contactformsurfacecontroller> ("HandleContactForm")) { @Html.ValidationSummary(true) @Html.AntiForgeryToken() @Html.TextBoxFor(model => model.Name, new { placeholder = "Your Name" }) @Html.ValidationMessageFor(model => model.Name) @Html.TextBoxFor(model => model.Email, new { placeholder = "Email Address" }) @Html.ValidationMessageFor(model => model.Email) <input type="submit" value="Send" /> }
What error do you get ?
Dave
Hi Dave,
Its giving error type or namespace contactformsurfacecontroller could not be found.
Manisha
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
MVC model error in Controllers
Hi,
My controller is not getting model in MVC Umbraco,Its giving error in Modelname.
Adding my code:
public class ContactFormSurfaceController : SurfaceController { public ActionResult RenderContactForm() {
}
Hi
Could you add your Partial View Code for ContactForm? I assume the Partial View is rendering your Contact Form Ok? from the below code?
Just be sure when you Render the ContactFrom on your View you are calling:
And then in your Partial View you should have this at the top:
To Post the forms contents you need something like this in the partial view:
Hi,
Thanks for your reply,I have added partial view and getting error in calling controller contactformsurfacecontroller.
Here is my code:
@model ContactFormViewModel @Html.Action("RenderContactForm", "ContactFormSurface") @using Umbraco.Web
What error do you get ?
Dave
Hi Dave,
Its giving error type or namespace contactformsurfacecontroller could not be found.
Manisha
is working on a reply...