【问题标题】:Umbraco MVC Error loading Partial View scriptUmbraco MVC 加载部分视图脚本时出错
【发布时间】:2013-09-09 20:32:44
【问题描述】:

我已经被困在这一点上一段时间了。表单很好,但没有验证。此外,当我点击提交时,我收到错误: “加载部分视图脚本时出错(文件:~/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; }
 }

宏部分文件:

@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> 
  }

【问题讨论】:

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


    【解决方案1】:

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

    当我在表单中评论该位时,进入控制器并未能验证“只能在使用时在 Http POST 的上下文中使用 UmbracoPageResult”等时出现另一个错误。

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

    在第二次运行重置操作时发布后,因为 通过传递一个新实例化的模型来维护模型状态,这 model 会继承 POST 中处理的模型的模型状态 操作(重置后)。

    在第二次调用重置操作时,由于令牌 数据已在令牌验证某处损坏 失败并且它永远不会到达返回部分的地步 查看。

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

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

    至少我回到了经过验证的表单,它正在验证,它不再在我的页面中,但我会把有趣的部分留给你。

    【讨论】:

    • 验证至少现在已经得到了积极的评价,但我仍然得到那个错误的唠叨
    【解决方案2】:

    很抱歉恢复一个旧线程,但我收到了类似的错误消息,这是由于数据库权限造成的。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-13
      • 2011-03-31
      • 2017-06-14
      • 2016-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多