I have this:
@Html.TextBoxFor(cModel => cModel.Value, new { id = "txtbLimit", @type = "int" })
And I want to make sure that what the user puts in there is an integer.
How can I do that?
EDIT: I dont parse this textBox with a value of a Model, so model validation is not what I want
EDIT2:
Model:
public class StorageConfigurationModel
{
[Required]
public int QueueMonitorConfigurationsID { get; set; }
[Required]
public PathType QueueMonitorConfigTypeName { get; set; }
[Required]
public string Location { get; set; }
[Required]
public UnitType QueueMonitorValueTypeName { get; set; }
[Required]
public ThresholdType Threshold { get; set; }
[Required]
[RegularExpression(@"\d*")]
public int Value { get; set; }
}
public enum PathType
{
Path
}
public enum UnitType
{
MB, GB, TB, Files, Percentage
}
public enum ThresholdType
{
Upper, Lower
}
Parse function:
private static StorageConfigurationModel BindToModel(int id, string pathType, string threshold, string valueType, string location, int limit)
{
return new StorageConfigurationModel
{
QueueMonitorConfigurationsID = id,
QueueMonitorConfigTypeName = (PathType)Enum.Parse(typeof(PathType), pathType),
Location = Convert.ToString(location.Trim()),
Value = Convert.ToInt32(limit),
QueueMonitorValueTypeName = (UnitType)Enum.Parse(typeof(UnitType), valueType),
Threshold = (ThresholdType)Enum.Parse(typeof(ThresholdType), threshold)
};
}
So when I put all the data in my view and click add, nothing is triggered.
With this I call the function that calls the modelbinder:
$.post('@Url.Action("AddUpdateConfigs")',
{id: @Model.QueueMonitorConfigurationsID , pathType: $('#ddlConfigTypeName').val(), threshold:$('#ddlThreshold').val(), valueType:$('#ddlValueTypeName').val(), location: $('#txtbLocation').val(), limit: $('#txtbLimit').val(), config: $('#NewOrUpdate').val() },
function(data){
if (!data.Success){
alert(data.Description);
}
else{
//$('#gridView').load('/Storage/gvConfigurations');
$.get('@Url.Action("gvConfigurations", "Storage")',null,function(data){$('#gridView').html(data);},'html');
}
},'json');