Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8060019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:51:08+00:00 2026-06-05T09:51:08+00:00

I am working on a project and i have some problem with my validation

  • 0

I am working on a project and i have some problem with my validation
Here is my model:

[ColumnMap("Guest_ID")]
public int Guest_ID { get; set; }

[ColumnMap("FirstName")]
[Required]
[Display(Name="FirstName")]
public  string FirstName { get; set; }

[ColumnMap("LastName")]
public string LastName { get; set; }

[ColumnMap("Phone")]
[Required]  
[MaxLength(10)]
public Nullable<int> Phone { get; set; }

[ColumnMap("AdrOras")]
[Required]
public string AdrOras { get; set; }

So I have required on FirstName and Phone and also MaxLength=10 on Phone.

Here is my CreateReservation method in my controller:

public ActionResult CreateReservation(int? RoomID, string FirstName, string LastName,int? Phone,string Oras,string Judet,string Tara,string Strada,int? GuestTypeId,DateTime? Birthday,DateTime? Data_Check_in, DateTime? Data_Check_out) 
{
    DBContext.Current.Open();
    Reservation rezervare = new Reservation();
    string  username= User.Identity.Name;
    Users user=Users.UserbyUsername(username);
    if(!string.IsNullOrEmpty(RoomID.ToString())&&!string.IsNullOrEmpty(FirstName)&&!string.IsNullOrEmpty(LastName)&&Phone.HasValue&&!string.IsNullOrEmpty(Judet)&&!string.IsNullOrEmpty(Tara)&&!string.IsNullOrEmpty(Strada)&&!string.IsNullOrEmpty(GuestTypeId.ToString())&&Birthday.HasValue&&Data_Check_in.HasValue&& Data_Check_out.HasValue)
    {
        rezervare.CreazaRezervare(RoomID, FirstName, LastName, Phone, Oras, Judet, Tara, Strada, GuestTypeId, Birthday,user.UserID,Data_Check_in, Data_Check_out);
        return RedirectToAction("MyReservation","Reservation");
    }

    var model = GuestTyp.SelectAll();
    ReservationView rez = new ReservationView()

    {
        rezervare =rezervare,
        client = model.ToList()
    };

    DBContext.Current.Close();
    return View(rez);
}

And here is my view :

@model LicentaTest.Models.ReservationView
@using JQueryUIHelpers

@{
    ViewBag.Title = "Checkout";
}

<head>
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="../../Scripts/jquery-ui-1.8.19.min.js" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui.unobtrusive.min.js")" type="text/javascript"></script>   
    <script src="../../Scripts/jquery-ui.unobtrusive-0.5.0.min.js" type="text/javascript"></script>
</head>

<script type="text/javascript">
    $(function () {
        $('input[type=text], textarea, input[type=password]').width(200);
        $('#valSum').hide();
        $('form').bind('invalid-form.validate', function (error, element) {
            $('#valSum').show("slow");
            return false;
        });
    });
</script>

@if (!ViewData.ModelState.IsValid) {
    <script type="text/javascript">
        $(function () {
            $('#valSum').show("slow");
        });
    </script>
}

@using (Html.BeginForm("CreateReservation", "Reservation", FormMethod.Post))
{
    @Html.ValidationSummary(true)
    <form class="form">
    <div class = "styler">
    <div id = "valSum" class="ui-state-error ui-corner-all" style="padding: 0 .7em;width:500px">    
</div>
    <h6>Completare Date Rezervare</h6>
    <fieldset class="ui-widget">
        <legend class="ui-state-legend-default ui-corner-top ui-corner-bottom">Date personale</legend>
            @Html.Hidden("RoomID")  
            <div class="editor-label">
                @Html.Label("FirstName")
                @Html.TextBox("FirstName") 
                @Html.ValidationMessage("FirstName","Numele trebuie introdus")
            </div>
            <div class="editor-label">
                @Html.Label("LastName    ")
                @Html.TextBox("LastName") 
            </div>
            <div class="editor-label">
                @Html.Label("Phone")
                @Html.TextBox("Phone")  
                @Html.ValidationMessage("Phone","Numarul trebuie sa fie din maxim 10 cifre")
            </div>
            <div class="editor-label">
                @Html.Label("Data Nasterii")
                @(Html.JQueryUI().Datepicker("Birthday").MaxDate(DateTime.Now))
            </div>
            <div class="editor-label">
                @Html.Label("Tip CLient")
                @Html.DropDownList("GuestTypeID", new SelectList(Model.client.AsEnumerable(), "GuestTypeID", "GuestType"))
            </div>
        </fieldset>
    <fieldset class="ui-widget">
    <legend class="ui-state-legend-default ui-corner-top ui-corner-bottom">Adresa</legend>
        <div class="editor-label">
            @Html.Label("Tara")
            @Html.TextBox("Tara")
        </div>
        <div class="editor-label">
            @Html.Label("Oras")
            @Html.TextBox("Oras")
            @Html.ValidationMessage("Oras","Field is required")
        </div>
        <div class="editor-label">
            @Html.Label("Judet")
            @Html.TextBox("Judet")
        </div>
        <div class="editor-label">
            @Html.Label("Strada")
            @Html.TextBox("Strada")
        </div>
    </fieldset>
    <fieldset class="ui-widget">
        <legend class="ui-state-legend-default ui-corner-top ui-corner-bottom">Perioada rezervare</legend>
        <div class="editor-label">
            @Html.Label("Data Intrare")
            @Html.JQueryUI().Datepicker("Data_Check_in")
        </div>
        <div class="editor-label">
            @Html.Label("Data Iesire")
            @Html.JQueryUI().Datepicker("Data_Check_out")
        </div>
    </fieldset>

    <p>
        <input type="submit" value="Create" />
    </p>

    <div>
        @Html.ActionLink("Back to List", "Index", "Guest")
    </div>
    </div>
    </form>
}

When i push create button the maxlenght validation is working but the required field validation is not working
enter image description here

Why is this happening what am i doing wrong

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:51:10+00:00Added an answer on June 5, 2026 at 9:51 am

    You have 2 forms nested inside each other. You cannot have nested forms.

    You have:

    @using (Html.BeginForm("CreateReservation", "Reservation", FormMethod.Get)){
        <form>...</form>
    }
    

    Remove the <form></form> tags

    Also…
    I don’t see a script tag for jQuery in your head section

    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="../../Scripts/jquery-ui-1.8.19.min.js" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui.unobtrusive.min.js")" type="text/javascript"></script>   
    <script src="../../Scripts/jquery-ui.unobtrusive-0.5.0.min.js" type="text/javascript"></script>
    

    Try this…

    Get jQuery and jQuery UI from CDN

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js" type="text/javascript"></script>
    

    Then these three need to be in this order. And ALWAYS use @Url.Content(...) for your scripts

    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a project which have some charts (graphs), tick chart, candlestick
I'm working on a windows phone project where I have some xml files with
I'm working on a JPA project in which I have some different Entities extending
I am working on a project on WPF and I have to create some
I have been working on a project locally and at some point I gave
I have a django project, but for some reason basic jquery isn't working. <html>
I have an Android project in eclipse IDE which was working. After some imports
I working on project and have problem with threading and update of UI. I
I have this problem in a project I'm working on: I have a list
i'm working on a project and i have some problems.I have searched but can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.