このチュートリアルに従って、umbraco v6 で連絡先フォームを作成しようとしています。私が抱えている問題は、a) フォームがロード時に投稿されているようです。デフォルトでは、フォームに必須フィールドのエラーが表示されます。b) 実際にデータを入力して送信すると、次の場所で 404 not found エラーが発生します: Requested URL: /umbraco/RenderMvc
これが私のモデルのコードです:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using System.Web.Security;
using umbraco.cms.businesslogic.member;
using System.ComponentModel.DataAnnotations;
namespace CustomControls
{
public class ContactFormModel
{
[Required, Display(Name = "First name")]
public string FirstName { get; set; }
[Required, Display(Name = "Surname")]
public string Surname { get; set; }
[Required, Display(Name = "Company")]
public string Company { get; set; }
[Required, Display(Name = "Email address")]
[DataType(DataType.EmailAddress)]
public string EmailAddress { get; set; }
[Required, Display(Name = "Telephone")]
public string Telephone { get; set; }
}
}
ここに私のSurfaceControllerコードがあります:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using System.Web.Security;
using umbraco.cms.businesslogic.member;
using System.ComponentModel.DataAnnotations;
namespace CustomControls
{
public class ContactFormSurfaceController : Umbraco.Web.Mvc.SurfaceController
{
[HttpGet]
[ActionName("ContactForm")]
public ActionResult ContactFormGet(ContactFormModel model)
{
return PartialView("ContactForm", new ContactFormModel());
}
[HttpPost]
[ActionName("ContactForm")]
public ActionResult ContactFormPost(ContactFormModel model)
{
//model not valid, do not save, but return current umbraco page
if (!ModelState.IsValid)
{
//Perhaps you might want to add a custom message to the ViewBag
//which will be available on the View when it renders (since we're not
//redirecting)
TempData.Add("Status", "Invalid form data");
//return CurrentUmbracoPage();
return RedirectToCurrentUmbracoPage();
}
//if validation passes perform whatever logic
//In this sample we keep it empty, but try setting a breakpoint to see what is posted here
//Perhaps you might want to store some data in TempData which will be available
//in the View after the redirect below. An example might be to show a custom 'submit
//successful' message on the View, for example:
TempData.Add("Status", "Your form was successfully submitted at " + DateTime.Now);
//redirect to current page to clear the form
return RedirectToCurrentUmbracoPage();
//Or redirect to specific page
//return RedirectToUmbracoPage(1063);
}
}
}
そして最後に、これが私の見解です:
@model CustomControls.ContactFormModel
@using(Html.BeginUmbracoForm("SubmitContactForm", "ContactFormSurface"))
{
@Html.EditorFor(x => Model)
<input type="submit"/>
}
<p class="field-validation-error">@TempData["Status"]</p>
これは、フォームをレンダリングするためにテンプレートで使用しているコードのスニペットです。
@Html.Action("ContactForm","ContactFormSurface")
私が間違っているところを指摘できる人はいますか?
ありがとう