Umbraco MVC加载部分视图脚本时出错

时间:2013-09-09 20:32:45

标签: asp.net-mvc asp.net-mvc-4 razor umbraco

我一直被困在这一点上。表格很好,但没有验证。当我点击提交时,我收到错误:  “加载部分视图脚本时出错(文件:〜/ Views / MacroPartials / ApplicationFormStub.cshtml)”

我不太确定我哪里出错了,并且非常感谢您就正确的方向获取表格进行验证和至少通过。

这是我的模特:

[MetadataType(typeof(ApplicationMetaData))]
public partial class Application { }
public class ApplicationMetaData
{
    [DisplayName("Employer Name")]
    [Required (ErrorMessage="Please Enter the Employer's Name")]
    [StringLength(50, ErrorMessage = "Only 50 Characters allowed")]
    public string EmployerName { get; set; }

    [DisplayName("Supervisor Name")]
    [Required (ErrorMessage="Please Enter the Supervisor's Name")]
    [StringLength(50, ErrorMessage = "Only 50 Characters allowed")]
    public string SupervisorName { get; set; }

    [DisplayName("Supervisor Title")]
    [Required (ErrorMessage="Please Enter the Supervisor's Title")]
    [StringLength(50, ErrorMessage = "Only 50 Characters allowed")]
    public string SupervisorTitle { get; set; }

    [DisplayName("Employer Address")]
    [Required (ErrorMessage="Please Enter the Employer's Address")]
    [StringLength(50, ErrorMessage = "Only 50 Characters allowed")]
    public string EmployerAddress { get; set; }

    [DisplayName("Employer City")]
    [Required (ErrorMessage="Please Enter the Employer's City")]
    [StringLength(50, ErrorMessage = "Only 50 Characters allowed")]
    public string EmployerCity { get; set; }

    [DisplayName("Employer State")]
    [Required (ErrorMessage="Please Enter the Employer's State")]
    [StringLength(50, ErrorMessage = "Only 50 Characters allowed")]
    public object EmployerState { get; set; }

    [DisplayName("Employer Zip")]
    [Required (ErrorMessage="Please Enter the Employer's Zip")]
    [StringLength(50, ErrorMessage = "Only 50 Characters allowed")]
    public string EmployerZip { get; set; }

    [DisplayName("Employer Phone")]
    [StringLength(10, ErrorMessage = "Only 10 Characters allowed")]
    public string EmployerPhone { get; set; }
 }

Macro Partials文件:

@Html.Action("ShowApplication", "ServicesSurface")

表面控制器:

 [HttpGet]
    [ActionName("ShowApplication")]
    public ActionResult ShowApplication()
    {           
        return PartialView("ServicesApplicationForm", new ApplicationMetaData());
    }

    [HttpPost]
    [ValidateAntiForgeryToken]
    [ActionName("ShowApplication")]
    public ActionResult ShowApplication(ApplicationMetaData Model)
        {
         if (!ModelState.IsValid)
            {
                return CurrentUmbracoPage();
            }

         try
             {
              //Linq Data Entry
             }
         catch (Exception oe)
             {
             Response.Write(oe.Message);
             Response.End();
             }
         //Send Email 
         return RedirectToAction(RedirectUrl);
        }

查看:

@using Umbraco.Web
@using UmbracoProd.code
@model Umbraco.Services.ApplicationMetaData

<script src="@Url.Content("/../../scripts/libs/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("/../../scripts/libs/jquery/jquery.validate.min.js")" type="text/javascript"></script>
<link href="@Url.Content("/../../css/Services/form.css")" rel="stylesheet" type="text/css" />


@using (Html.BeginUmbracoForm("ShowApplication", "ServicesSurface"))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

<div class="FormArea">
    <fieldset>
        <legend>Section One</legend>
        <ul>
            <li>
                @Html.LabelFor(x => x.EmployerName)
                @Html.TextBoxFor(x => x.EmployerName)
            </li>
            <li>
                @Html.ValidationMessageFor(x => x.EmployerName)
            </li>
            <li>
                @Html.LabelFor(x => x.SupervisorName)
                @Html.TextBoxFor(x => x.SupervisorName)
            </li>
            <li>
                @Html.ValidationMessageFor(x => x.SupervisorName)
            </li>
            <li>
                @Html.LabelFor(x => x.SupervisorTitle)
                @Html.TextBoxFor(x => x.SupervisorTitle)
            </li>
             <li>
                @Html.ValidationMessageFor(x => x.SupervisorTitle)
            </li>
            <li>
                @Html.LabelFor(x => x.EmployerAddress)
                @Html.TextBoxFor(x => x.EmployerAddress)
            </li>
            <li>
                @Html.ValidationMessageFor(x => x.EmployerAddress)
            </li>
            <li>
                @Html.LabelFor(x => x.EmployerCity)
                @Html.TextBoxFor(x => x.EmployerCity)
            </li>
            <li>
                @Html.ValidationMessageFor(x => x.EmployerCity)
            </li>
            <li>
                @Html.LabelFor(x => x.EmployerState)                    
                @Html.StateDropDownList("EmployerState", "IN")
            </li>
            <li>
                @Html.ValidationMessageFor(x => x.EmployerState)
            </li>
            <li>
                @Html.LabelFor(x => x.EmployerZip)
                @Html.TextBoxFor(x => x.EmployerZip)
            </li>
            <li>
                @Html.ValidationMessageFor(x => x.EmployerZip)
            </li>
            <li>
                @Html.LabelFor(x => x.EmployerPhone)
                @Html.TextBoxFor(x => x.EmployerPhone)
            </li>
            <li>
                @Html.ValidationMessageFor(x => x.EmployerPhone)
            </li>                              
        </ul>
    </fieldset>        
  <input type="submit" class="button" value="Submit"/>
  </div> 
  }

2 个答案:

答案 0 :(得分:0)

我收到一条错误消息,说ApplicationMetaData没有@ Html.StateDropDownList()的定义。

当我从表单中注释掉那个位置后,我进入控制器并且无法验证哪个“在使用”等时只能在Http POST的上下文中使用UmbracoPageResult时出现了另一个错误。

我基本上从here找到了答案:

  

第二次运行重置动作后的帖子,因为   通过传递一个新实例化的模型来维护modelstate   model将继承POST中处理的模型的模型状态   动作(PostReset)。

     

在第二次调用重置操作时,因为令牌   数据已经在令牌验证的某处被破坏   失败,它永远不会到达返回部分的地步   图。

即。不要创建另一个模型发回相同的模型,我将ShowApplication POST中失败的验证代码更改为

    if (!ModelState.IsValid)
    {
        return PartialView("ServicesApplicationForm", Model);
    }

并且至少我回到了经过验证的表格,经过验证,它不再出现在我的页面中,但我会给你留下有趣的一点。

答案 1 :(得分:0)

很抱歉复活旧线程,但我收到了类似的数据库权限错误消息。

我启用了SQL Server身份验证,并且我创建的用户没有对数据库的执行权限,我授予了权限,错误消失了。

也许这会对某人有所帮助。