Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Manisha Singla 17 posts 97 karma points
    May 11, 2018 @ 06:37
    Manisha Singla
    0

    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() {

        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();
    }
    

    }

  • Neil Hodges 320 posts 926 karma points
    May 11, 2018 @ 09:13
    Neil Hodges
    1

    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" })
    }
    
  • Manisha Singla 17 posts 97 karma points
    May 11, 2018 @ 11:25
    Manisha Singla
    0

    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

    @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" />
    }
    
  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    May 11, 2018 @ 12:21
    Dave Woestenborghs
    0

    What error do you get ?

    Dave

  • Manisha Singla 17 posts 97 karma points
    May 11, 2018 @ 12:45
    Manisha Singla
    0

    Hi Dave,

    Its giving error type or namespace contactformsurfacecontroller could not be found.

    Manisha

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies