从模型mvc 2渲染控制

时间:2012-09-16 14:39:35

标签: c# asp.net-mvc asp.net-mvc-2

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

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来说是不好的做法?

有什么想法吗?

0 个答案:

没有答案