asp.net-mvc – Basic Umbraco 6.1.1 SurfaceController问题
我搜索了所有可以找到的教程,我仍然遇到Umbraco Surface控制器的问题.我已经创建了一个简单的表面控制器示例,该示例有效,但有一些问题.这是我的代码到目前为止,要遵循的问题:
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") 我的问题: >我很确定返回ContactFormGet(模型)是错误的 当我尝试返回RedirectToCurrentUmbracoPage()时,我得到了不能 当我尝试返回CurrentUmbracoPage()时,我得到的只能使用 我敢肯定我错过了一些令人难以置信的愚蠢的东西,但我无法想象我的生活. 解决方法
我想花点时间说出我是如何解决这个问题的.在玩了一些之后,我意识到我并没有清楚地说出我的问题.基本上,我要做的就是在部分视图宏中嵌入MVC表单,以便它可以用在页面的内容中(不嵌入模板中).
我可以让this solution工作,但我真的不喜欢作者在View文件中放了多少逻辑.所以我这样修改了他的解决方案: 部分视图宏(cshtml)文件: @inherits Umbraco.Web.Macros.PartialViewMacroPage @using Intrepiware.Models @{ bool isPostback = !String.IsNullOrEmpty(Request.Form["submit-button"]); if(isPostback) { @Html.Action("CreateComment","ContactSurface",Request.Form) } else { @Html.Partial("~/Views/Partials/ContactForm.cshtml",new ContactFormModel()) } } 表单部分视图(cshtml)文件: @using Intrepiware.Models @using Intrepiware.Controllers @model ContactFormModel <p> <span style="color: red;">@TempData["Errors"]</span> </p> <p> @TempData["Success"] </p> <div id="cp_contact_form"> @using(Html.BeginUmbracoForm("CreateComment","BlogPostSurface")) { @* Form code goes here *@ } ContactSurfaceController.cs文件: public class ContactSurfaceController : Umbraco.Web.Mvc.SurfaceController { [HttpPost] [ValidateAntiForgeryToken] public ActionResult ubCreateComment(ContactFormModel model) { if (processComment(model) == false) return CurrentUmbracoPage(); else return RedirectToCurrentUmbracoPage(); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult CreateComment(ContactFormModel model) { if(processComment(model) == true) { TempData["Success"] = "Thank you for your interest. We will be in contact with you shortly."; ModelState.Clear(); } return PartialView("~/Views/Partials/ContactForm.cshtml"); } private bool processComment(ContactFormModel model) { // Handle the model validation and processing; return true if success } } 控制器的设计使得表单可以嵌入模板或部分视图宏中.如果它嵌入在模板中,表单应该发布到ubCreateComment;如果它在宏中,则发布到CreateComment. 我几乎肯定有一个更好/更正确的方法,但我没有时间去研究这个项目.如果有人有更好的解决方案,请发布! 最后一个问题/注意:您会注意到局部视图宏将Request.Form发布到ContactSurfaceController.CreateComment,而MVC为我神奇地序列化它.那是安全的,是吗?如果是这样,MVC不摇滚吗? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 即使ReadOnly设置为false,ASP.NET GridView中的CheckBoxFie
- asp.net-web-api – Web Api gzip压缩
- asp.net-mvc – MVC4 SimpleMemberhip’提供商遇到了未知错
- asp.net-web-api – 使用Fiddler进行包含OData命令的HTTP G
- 从ASP.Net WebSite转换为Web应用程序项目后的MasterType问题
- asp.net-mvc-2 – 在MVC 2中使用自定义TextWriter时,“Bina
- asp.net-mvc-3 – 在ASP.NET MVC中使用多个部分时重复输入i
- 获取所选的输入类型单选按钮ASP.NET
- asp.net-mvc – 在ASP.Net MVC 2中为非归因模型验证提供本地
- asp.net mvc 3:使用图像管理模型的最佳方式
- 如何在ASP.NET应用程序中使用CSS
- asp-classic – <%%>和<%=%>之间有什么区别?
- asp.net-web-api – 从数据存储实现动态OAuthBea
- asp.net – maxAllowedContentLength不适用于IHt
- asp.net-mvc-3 – 剃刀引擎 – 如何根据不同的条
- asp.net – 如何让用户登录2周?
- asp.net-mvc-4 – 为什么我们需要MVC中的Web API
- asp.net-mvc-2 – 如何在MVC.NET 2中使用ReportV
- asp.net-mvc – jqGrid中的日期选择器,简单的例子
- WPAD查询从ASP.NET调用webservice