利用可能なすべてのチュートリアルを検索しましたが、Umbraco Surface Controller でまだ問題が発生しています。最低限の Surface Controller の例を作成しましたが、これはある程度機能しますが、いくつかの問題があります。これまでの私のコードは次のとおりです。質問は次のとおりです。
ContactformModel1.cs:
public class ContactFormModel1
{
public string Email { get; set; }
public string Name { get; set; }
public string HoneyPot { get; set; }
public string Title { get; set; }
public string Last { get; set; }
public string First { get; set; }
public string Addr { get; set; }
public string Phone { get; set; }
public string Time { get; set; }
public string Comment { get; set; }
}
ContactSurfaceController.cs:
public class ContactSurfaceController : Umbraco.Web.Mvc.SurfaceController
{
public ActionResult Index()
{
return Content("this is some test content...");
}
[HttpGet]
[ActionName("ContactForm")]
public ActionResult ContactFormGet(ContactFormModel1 model)
{
return PartialView("~/Views/ContactSurface/Contact1.cshtml", model);
}
[HttpPost]
[ActionName("ContactForm")]
public ActionResult ContactFormPost(ContactFormModel1 model)
{
// Return the form, just append some exclamation points to the email address
model.Email += "!!!!";
return ContactFormGet(model);
}
public ActionResult SayOK(ContactFormModel1 model)
{
return Content("OK");
}
}
Contact.cshtml:
@model ContactFormModel1
@using (Html.BeginUmbracoForm<ContactSurfaceController>("ContactForm"))
{
@Html.EditorFor(x => Model)
<input type="submit" />
}
ContactMacroPartial.cshtml:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@Html.Action("ContactForm", "ContactSurface")
私の質問:
ContactFormPost メソッドでそれが間違っていると確信して
return ContactFormGet(model)いますが、私が試した他のすべてはエラーをスローします。試してみると
return RedirectToCurrentUmbracoPage()、 が得られCannot find the Umbraco route definition in the route values, the request must be made in the context of an Umbraco requestます。試してみると
return CurrentUmbracoPage()、 が得られCan only use UmbracoPageResult in the context of an Http POST when using a SurfaceController formます。ルーティングは正しく機能しているように見えます (ContactFormPost 内にブレークポイントを配置すると、デバッガーはそこで停止します)。しかし、フォームが戻ってくると、送信した正確な値が得られます。見えない!!! メールアドレスに追加されます。(注: このコードはデバッグ用であり、何か役に立つことを意図したものではありません)。
コントローラーで「SayOK」メソッドを呼び出すにはどうすればよいですか? BeginUmbracoForm メソッドを SayOK を指すように変更しても、ContactFormPost メソッドでスタックしてしまいます。
私は信じられないほど愚かな何かを見逃していると確信していますが、私の人生ではこれを理解することはできません.