Cybercrux

Everything is achievable through technology

Form Post

Umbraco Form ,perfectly working workflow

Step 1. Create the Model;

public class CommentViewModel
{
[Required]
public string Name { get; set; }

[Required]
public string Email { get; set; }

[Required]
[Display(Name = “Enter a comment“)]
public string Comment { get; set; }
}

step 2. Create Controller with inherit SurfaceController

public class BlogPostSurfaceController : SurfaceController
{
[HttpPost]
public ActionResult CreateComment(CommentViewModel model)
{

if (!ModelState.IsValid)
{
return CurrentUmbracoPage();

}

TempData.Add(“CustomMessage”, “Your form was successfully submitted at ” + DateTime.Now);

return RedirectToCurrentUmbracoPage();

}

}

step 3.  Create Partial view as below

@inherits Umbraco.Web.Mvc.UmbracoViewPage<umbracomvc.Models.CommentViewModel>
@{
Layout = null;
}

@using(Html.BeginUmbracoForm(“CreateComment”, “BlogPostSurface”))
{
@TempData[“CustomMessage”]
<div class=”editor-label”>
@Html.LabelFor(x => Model.Name)
</div>
<div class=”editor-field”>
@Html.TextBoxFor(x => Model.Name)
@Html.ValidationMessageFor(x => Model.Name)
</div>

<div class=”editor-label”>
@Html.LabelFor(x => Model.Email)
</div>
<div class=”editor-field”>
@Html.TextBoxFor(x => Model.Email)
@Html.ValidationMessageFor(x => Model.Email)
</div>

<div class=”editor-label”>
@Html.LabelFor(x => Model.Comment)
</div>
<div class=”editor-field”>
@Html.TextAreaFor(x => Model.Comment)
@Html.ValidationMessageFor(x => Model.Comment)
</div>
<input type=”submit”/>
}

Step 4. Call the partial view inside the required view

@Html.Partial(“Navigation”, new umbracomvc.Models.CommentViewModel() )

everythning is working fine for me 🙂

Leave a comment