0

我有一个模型,其中包含我在构造函数中生成的控制器。这个例子有点简化,但它应该解释模型的外观

public class ContactFormViewModel : ViewUserControl
{
    public ContactFormViewModel()
    {
        ContactCaptchaControl = new CaptchaControl()
        {
            CaptchaLength = 5
        };
    }

    [Required(ErrorMessage = "Please enter your name")]
    public string Name { get; set; }

    [Required(ErrorMessage = "Please enter the Captcha")]
    public string Captcha { get; set; }

    public CaptchaControl ContactCaptchaControl { get; set; }
}

现在,视图看起来像这样

<%@ Control Language="C#" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewUserControl<MVC.Models.Contact.ContactFormViewModel>" %>

<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("Add", "Contact", FormMethod.Post, new { id = "frmContact", OnSubmit = "return false;" }))
   {%>
Name:
    <%: Html.TextBoxFor(model => model.Name, new { @class = "BendsoftTextbox" }) %>
    <%: Html.ValidationMessageFor(model => model.Name) %>

Captcha:
    <%: Html.DisplayFor(model => model.ContactCaptchaControl) %>

<% } %>
<% Html.EndForm(); %>

我的问题是控件(ContactCaptchaControl)没有按我想要的方式呈现,也许这对 mvc 来说是不好的做法?

有什么想法吗?

4

0 回答 0