[英]Html.ValidationMessageFor on Mono has strange results
我是ASP.NET的初學者,正在通過本教程學習如何使用它。 我使用Linux,所以我使用的是Mono 2.6.7。 我不得不偏離本教程的路徑幾次才能在Mono下工作(包括使用我鏈接到的MVC 2補丁版,但由於新用戶只能發布一個超鏈接,所以我無法這樣做) ,但是有一個我無法解決的問題:表單驗證。 我這樣設置驗證元數據:
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
namespace MvcMusicStore.Models
{
[MetadataType(typeof(AlbumMetaData))]
public partial class Album
{
[Bind(Exclude = "AlbumID")]
public class AlbumMetaData
{
[ScaffoldColumn(false)]
public object AlbumID { get; set; }
[DisplayName("Genre")]
public object GenreID { get; set; }
[DisplayName("Artist")]
public object ArtistID { get; set; }
[Required(ErrorMessage = "An Album Title is required")]
[StringLength(160)]
public object Title { get; set; }
[DisplayName("Album Art URL")]
[StringLength(1024)]
public object AlbumArtUrl { get; set; }
[Required(ErrorMessage = "Price is required")]
[Range(0.01, 100.00, ErrorMessage = "Price must be between 0.01 and 100.00")]
public object Price { get; set; }
}
}
}
我這樣設置我的視圖:
<p>
<%= Html.LabelFor(model => model.Title) %>
<%= Html.TextBoxFor(model => model.Title) %>
<%= Html.ValidationMessageFor(model => model.Title) %>
</p>
<p>
<%= Html.LabelFor(model => model.Price) %>
<%= Html.TextBoxFor(model => model.Price) %>
<%= Html.ValidationMessageFor(model => model.Price) %>
</p>
<p>
<%= Html.LabelFor(model => model.AlbumArtUrl) %>
<%= Html.TextBoxFor(model => model.AlbumArtUrl) %>
<%= Html.ValidationMessageFor(model => model.AlbumArtUrl) %>
</p>
但是,當我通過提供不正確的數據來測試表單時,沒有得到我設置的錯誤消息。 當我將“標題”留為空白時,我得到:“驗證錯誤(System.ComponentModel.DataAnnotations.RequiredAttribute):標題”,而當我將價格留為空白時,我也得到了類似的錯誤。 如果我為“價格”輸入了超出范圍的數字,或者為“標題”或“ AlbumArtUrl”輸入了長字符串,則腳本將忽略該問題,不留下錯誤消息,並讓表單提交; 但是,如果在“價格”中輸入一個非常大的數字,則會得到“該值' 大數字 '無效。”。
我怎樣才能解決這個問題? 我可以使用Html.ValidationMessageFor的替代方法嗎? 我的模型有問題嗎? Mono只是一個問題嗎? 請幫忙!
看起來[Required]和[Range]屬性實際上並沒有在Mono中實現。 它們只是存根,以便您可以編譯應用程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.