我看到一个类似的职位,试图这样做同样的事情的晚餐的例子,但他固定他的问题,我似乎是一个小小的更深。基本上我cxan得到验证工作只是好的,但它只能在火狐。在IE7时页载荷,我立即获得警报箱的下列信息:"错误:元件的标题不在的一种形式"...它显然是在形式在这里,如果需要的话我可以张贴的标记实际上是从图源,以显示这一点。任何想法什么我可以做些什么来解决这将是最理解!

基本上我只是想确保我NewsPost有一个标题和一体。因为我包裹在的模型我想即不太明白这一点。也许我是错误的。

我使用xVal我的验证。我是传递一个模型在为我的模型。我的视图模型,看起来是这样的:

public class NewsAdminViewData : ViewModel
{
   public NewsPost NewsPost { get; set; }
   public List<SelectListItem> NewsItem { get; set; }
   public List<SelectListItem> NewsGroup { get; set; }

   public NewsAdminViewData(List<SelectListItem> newsItem, List<SelectListItem> newsGroup, NewsPost newsPost)
   {
      this.NewsItem = newsItem;
      this.NewsGroup = newsGroup;
      this.NewsPost = newsPost;
   }
}

这里是我的观点:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MVCApp.Models.ViewModels.News.NewsAdminViewData>" %>

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <% using (Html.BeginForm())
           {%>
        <div class="moduleContainer">
            <div class="moduleTitle">
                Create News Item
            </div>
            <div class="moduleContent">
                <div>
                    <div>
                        Title:</div>
                    <div>
                        <%= Html.TextBox("Title") %>
                    </div>
                </div>
                <div>
                    <div>
                        &nbsp;</div>
                    <div>
                        <%= Html.TextArea("Body") %>
                    </div>
                </div>
                <div>
                    <div>
                        News Group:
                    </div>
                    <div>
                        <%= Html.DropDownList("NewsGroup")%>
                    </div>
                </div>
                <div>
                    <div>
                        News Item:
                    </div>
                    <div>
                        <%= Html.DropDownList("NewsItem") %>
                    </div>
                </div>
            </div>
            <div class="moduleFooter">
                <%= Html.SubmitButton("btnSubmit", "Add News Post", null, "To add this news post click here.", "#ffd40f")%>
            </div>
        </div>
        <% } %>
        <%= Html.ClientSideValidation<NewsPost>()%>

最后我后的行动:

 [AcceptVerbs(HttpVerbs.Post)]
    public virtual ActionResult Create(/*FormCollection collection*/ NewsPost np)
    {
       NewsPost entity = this.reposNewsPost.New();
       try
       {
          entity.Title = np.Title; 
          entity.NewsPostGUID = System.Guid.NewGuid();
          entity.DateAdded = DateTime.Now;
          entity.DateUpdated = DateTime.Now;
          entity.Body = np.Body; 

          UpdateModel(entity);
          this.reposNewsPost.Insert(entity);
          this.reposNewsPost.SubmitChanges();
          return RedirectToAction("Index");
        }
        catch (RulesException ex)
        {
           ex.AddModelStateErrors(ModelState, "NewsPost");
           return ModelState.IsValid ? RedirectToAction(MVC.News.Actions.Create) 
                        : (ActionResult)View();
        }
     }
有帮助吗?

解决方案

我遇到了类似的问题。老实说,它看起来并不像你做的烂摊子,因为我有,但也许它会直接你的解决方案。

我输入形式与xVal客户的验证是动态加载(jquery阿贾克斯呼叫)进入网页。不幸的是,我忽视的是,我将返回html成的元素已经形成'父母之间的元素。因为这是一个阿贾克斯的请求,嵌套'的形式'的元素其本的网页,并xVal方法"_attachRuleToDOMElement"是实现这样的:

 var parentForm = element.parents("form");
        if (parentForm.length != 1)// <-- there can be only one parent form of course
            alert("Error: Element " + element.attr("id") + " is not in a form");

我parentForm.lengts是2!

我看到你没有嵌套的形式在这里肯定的,但也许在主页上有什么?可能是IE7呈现嵌套的形式和火狐不。此外,我的名字输入控制不同,虽然这不应该被源的问题:

<%= Html.TextBox("np.Title") %>...<%= Html.TextBox("np.Body") %> etc...

然后我会elementPrefix:

<%= Html.ClientSideValidation<NewsPost>("np")%>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top