This project is read-only.

Two Submit buttons

Topics: Administration, General
Dec 18, 2013 at 7:14 AM
I am trying to create a view where i need to two different button calling two different controller methods. but when i place and run it gives me error.

"The required anti-forgery form field "__RequestVerificationToken" is not present."


@model Course.ViewModels.CourseIndexVM
    Layout.Title = T("Course").ToString();
@using(Html.BeginForm("Index", "CourseAdmin", FormMethod.Get)) {
    <fieldset class="bulk-actions">
        <label for="search">@T("Search:")</label>
        @Html.TextBoxFor(m => m.Search.Expression)
        <button type="submit">@T("Search")</button>
        <a href="@Url.Action("Index")">@T("Clear")</a>                     

@using (Html.BeginForm("Create", "CourseAdmin", FormMethod.Post))    
    <fieldset class="bulk-actions">
    <button type="submit">@T("Create")</button>

    <table class="items" summary="@T("List of Courses")">
            <col id="Col1" />
            <col id="Col2" />
            <col id="Col3" />
            <col id="Col4" />
            <col id="Col5" />
            <col id="Col6" />
                <th scope="col">@T("ID")</th>
                <th scope="col">@T("Name")</th>
                <th scope="col">@T("Description")</th>
        @foreach (var item in Model.Courses) {
                    <a href="@Url.Action("Edit", new {item.Id})" title="@T("Edit")">@T("Edit")</a>@T(" | ")                    
                    <a href="@Url.Action("Delete", new {item.Id, returnUrl = Request.Url.PathAndQuery})">@T("Delete")</a>                    


namespace CourseAdmin.Controllers
    public class CourseAdminController : Controller, IUpdateModel 
        private readonly IContentDefinitionService _contentDefinitionService;
        private readonly IRepository<CoursePartRecord> _coursePartRepository;
        private readonly IContentManager _contentManager;
        private readonly IProjectionManager _projectionManager;
        private readonly INotifier _notifier;
        private readonly IOrchardServices _orchardService;

        private dynamic Shape { get; set; }
        private readonly ISiteService _siteService;

         bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
            return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
        void IUpdateModel.AddModelError(string key, LocalizedString errorMessage) {
            ModelState.AddModelError(key, errorMessage.Text);

        public CourseAdminController(
            IShapeFactory shapeFactory, 
            ISiteService siteService, 
            IContentDefinitionService contentDefinitionService, 
            IContentManager contentManager, 
            IProjectionManager projectionManager, 
            IRepository<CoursePartRecord> coursePartRepository, 
            IOrchardServices orchardService,
            INotifier notifier)
            Shape = shapeFactory;
            _siteService = siteService;
            _contentDefinitionService = contentDefinitionService;
            _contentManager = contentManager;
            _projectionManager = projectionManager;
            _coursePartRepository = coursePartRepository;
            _notifier = notifier;
            _orchardService = orchardService;

        public ActionResult Create()
            var course = _orchardService.ContentManager.New("Courses");
            var editor = Shape.EditorTemplate(TemplateName: "Parts/Course.Create", Model: new CourseCreateVM(), Prefix: null);
            editor.Metadata.Position = "2";
            dynamic model = _orchardService.ContentManager.BuildEditor(course);

            // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
            return View((object)model);                                         

        [HttpPost, ActionName("Create")]
        public ActionResult CreatePOST(CourseCreateVM courseModel)
            var course = _orchardService.ContentManager.New("Courses");
            // Cast the customer to a UserPart
            var coursePart = course.As<CoursePart>();

            coursePart.Name = courseModel.Name;
            coursePart.Description = courseModel.Description;


            return RedirectToAction("Index");
Dec 18, 2013 at 7:22 AM
Instead of Html.BeginForm, use Html.BeginFormAntiForgeryPost.