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 6592823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:36:16+00:00 2026-05-25T17:36:16+00:00

I have created one page in MVC 3.0 Razor view. Create.cshtml @model LiveTest.Business.Models.QuestionsModel @*<script

  • 0

I have created one page in MVC 3.0 Razor view.
Create.cshtml

@model LiveTest.Business.Models.QuestionsModel
@*<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>*@
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <table cellpadding="1" cellspacing="1" border="0">
        <tr>
            <td>@Html.LabelFor(model => model.TestID)
            </td>
            <td>
                @Html.DropDownListFor(model => model.TestID, (IEnumerable<SelectListItem>)ViewBag.ItemIDList)@Html.ValidationMessageFor(model => model.TestID)
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(model => model.Question)
            </td>
            <td>@Html.EditorFor(model => model.Question)@Html.ValidationMessageFor(model => model.Question)
                @Html.HiddenFor(model => model.QuestionsID)
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(model => model.IsRequired)
            </td>
            <td>@Html.CheckBoxFor(model => model.IsRequired)@Html.ValidationMessageFor(model => model.IsRequired)
            </td>
        </tr>
        <tr>
            <td> 
            </td>
            <td>
                <input type="submit" value="Submit" />
            </td>
        </tr>
    </table>
}

QuestionsController.cs

 public class QuestionsController : Controller
    {
        #region "Attributes"
        private IQuestionsService _questionsService;
        #endregion

        #region "Constructors"
        public QuestionsController()
            : this(new QuestionsService())
        {
        }
        public QuestionsController(IQuestionsService interviewTestsService)
        {
            _questionsService = interviewTestsService;
        }
        #endregion
        #region "Action Methods"
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Create()
        {
            InterviewTestsService _interviewService = new InterviewTestsService();
            List<InterviewTestsModel> testlist = (List<InterviewTestsModel>)_interviewService.GetAll();
            ViewBag.ItemIDList = testlist.Select(i => new SelectListItem() { Value = i.TestID.ToString(), Text = i.Name });
            return View();
        }
        [HttpPost]
        public ActionResult Create(QuestionsModel questions)
        {
            if (ModelState.IsValid)
            {
                _questionsService.Add(questions);
                return RedirectToAction("Index");
            }
            InterviewTestsService _interviewService = new InterviewTestsService();
            List<InterviewTestsModel> testlist = (List<InterviewTestsModel>)_interviewService.GetAll();
            ViewBag.ItemIDList = testlist.Select(i => new SelectListItem() { Value = i.TestID.ToString(), Text = i.Name });
            return View(questions);
        }
        #endregion
    }

QuestionsModel.cs

public class QuestionsModel : IQuestionsModel
    {
        [ReadOnly(true)]
        public Guid QuestionsID { get; set; }

        [Required]
        [DisplayName("Question")]
        public string Question { get; set; }
        [DisplayName("Test ID")]
        public Guid TestID { get; set; }
        [DisplayName("Is Required")]
        public bool IsRequired { get; set; }
        [DisplayName("Created By")]
        public Guid CreatedBy { get; set; }
            }

Problem:

<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>

If I am adding the above two lines in Create.cshtml page and then I press submit button then it will fire validation message “Question is required!” if I am entering value in *Question field and then press submit button my [HttpPost]Create Method never execute.*

If I remove the above two lines from page then press submit button then it will execute [HttpPost]Create Method and fire validation from server side if I am entering value in Question field then also [HttpPost]Create executed.

Please help me.

  • 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-05-25T17:36:16+00:00Added an answer on May 25, 2026 at 5:36 pm

    The QuestionsModel class includes a property CreatedBy which is not included in your View.

    Try either adding CreatedBy as a hidden field, or (better yet) remove CreatedBy from the QuestionsModel class, since it is not an attribute which should be exposed in the view.

    I suspect that this missing property is the cause of the problem.

    UPDATE

    I ran some tests on your code, and it was not the CreatedBy property. Rather, your problem is that you are not supplying a QuestionsID value, but you included a hidden field for QuestionsID on the form.

    Because QuestionsID is a value type, by default, the DataAnnotationsModelValidatorProvider adds a Required validator to the QuestionsID field. Because the field did not have a ValidationMessage, you could not see the validation error.

    You can override the behavior of the default DataAnnotationsModelValidatorProvider by following the instructions in my answer here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one asp.net page. I want to add this page to asp.net mvc
I have created a one-time subscription in SSRS report manager 2008. However I keep
I have created a .NET DLL which makes some methods COM visible. One method
I have created an interface using jQuery UI Tabs, however one of my requirements
I have created a PHP-script to update a web server that is live inside
I have created a paginatedList and pager for that for my ASP.NET MVC project.
Ok, I have one JavaScript that creates rows in a table like this: function
Have created a c++ implementation of the Hough transform for detecting lines in images.
I have created a template for Visual Studio 2008 and it currently shows up
I have created a custom dialog for Visual Studio Setup Project using the steps

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.