Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67411

asp.net mvc 5, validation for not required fields(optional fields)

$
0
0

i've a form that some of the fields is not required to be filled or optional fields in asp.net mvc 5 application.

i've tried this things but, warning message for "this fields is required", keep showing.

[Required(AllowEmptyStrings = true)]
public string country { get; set; }

adding htmlAttribute
@required = false

Data Model

public class LoginViewModel
{
    ...

    public string country { get; set; }

    ...
}

Index.cshtml

@using (Html.BeginForm("Save", "SignUp", FormMethod.Post, new { name = "signUpForms", id = "signUpForm", @class = "registerLogin-form" }))
{
...
    if (Model.MembershipProgram.StsSignUpCountry)
    {
        <div class="form-group col-12">
           @Html.DropDownListFor(m => m.country, 
          new SelectList(Model.CountryLists, "CountryCode", "CountryName"),
          "Select Country",
            new
            {
                id = "select_country",
                @class = "form-control"
            })
        </div>
    }
...
<button type="submit" id="register-submit-btn" class="btn btn-primary pull-right active" name="command" value="Save">
            @ViewBag.JoinNow <i class="m-icon-swapright m-icon-white"></i>
</button>
}

Viewing all articles
Browse latest Browse all 67411

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>