您好我正在运行2个问题:
我正在使用requiredif属性,该属性适用于其他类型,如文本框,复选框等,但对于这个属性,它不起作用
[RequiredIf(“DoYouAgree”,ErrorMessage =“请上传图片徽标。”)] [DisplayName(“上传徽标”)] string imgfile {get;组; }
代码:
@*Browse File*@
<div class="clear"></div>
<div class="editor-label grid_2">
<br /><br /> @Html.LabelFor(model => model.imgfile):
</div>
<div style="margin-top:38px;" class="grid_2">
<input type="file" name="imgfile" id="imgfile" />
</div>
<div class="editor-label1 grid_3" style="margin-top:40px;margin-left:80px;" >
Max file size 299*299 px or 44KB
</div>
<br /><br /><br /><br />
<div class="grid_3 error long" style="margin-left:10px;">
@Html.ValidationMessageFor(model => model.imgfile)
</div>
<br />
为什么它不适合这个。
提前致谢!
[Required(ErrorMessage = "Please upload screenshot image.")]
[DisplayName("Screen Shots")]
public string ssimgfile { get; set; }
视图:
div style="margin-top:38px; margin-bottom:20px;" class="grid_2">
<input type="file" name="ssimgfile" id="ssimgfile" />
<div class="grid_3 error long" style="margin-left:4px;">
@Html.ValidationMessageFor(model => model.ssimgfile)
</div>
</div>
答案 0 :(得分:0)
I have done my work with javascript:
$(function () {
$('form').submit(function () {
if ($("input[type=radio]:checked").val() == "True") {
//Logo Image
var selectedFile = $('#imgfile').val();
if (selectedFile == "") {
alert('please select valid image logo for marketplace');
return false;
}
else {
var fileExtension = ['jpeg', 'jpg', 'png', 'gif', 'bmp'];
if ($.inArray($('#imgfile').val().split('.').pop().toLowerCase(), fileExtension) == -1) {
alert("You are permited to select only '\n.jpeg','.jpg', '.png', '.gif', '.bmp' formats are allowed.");
return false;
}
}