I have gone through previous posts on the same topic but I couldn't figure out what's wrong with my code. Here's my html
@model Models.Submissions
@{
ViewBag.Title = "Application";
}
@ViewBag.Title
@using (Html.BeginForm("Create","Submissions",FormMethod.Post))
{
@Html.ValidationSummary(true)
@Html.LabelFor(model => model.SubmissionId) | @Html.TextBoxFor(model => model.SubmissionId) |
@Html.LabelFor(model => model.SubmissionDate) | @Html.TextBoxFor(model => model.SubmissionId) |
}
@Html.ActionLink("Back to List", "Index")
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
Here's my controller. The button click doesn't trigger the http post method of the submissions controller . By the way, my controller is "SubmissionsController"
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(Submissions submission)
{
try
{
// TODO: Add insert logic here
// my logic
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
Thanks..! Help Appreciated
Talk1:
Your code looks OK. Are you sure your controller is not being hit? Have you put a breakpoint on the first line to check?
Talk2:
I think you're wanting SubmissionDate in your second textbox. Can you show the view model?
Talk3:
@Html.ValidationSummary(true) means to display only errors not directly associated with a property (which means you also need to include @Html.ValidationMessageFor() for each property), otherwise use @Html.ValidationSummary(false)
Talk4:
Thanks StephenMuecke and Jonesy for your valuable inputs. The problem was due the @scripts.render part in my code that was causing client side validation. I have disabled it and and now it is working fine.
Solutions1
Seems you're trying to include jquery validation for the form as well, so my humble guess would be, that your client-side validation prevents postback to the server due to a validation error. Try to disable that validation and try again. Can't provide more info, because I don't know what exactly does your javascript do, but I think you should be able to fix it yourself now.
And as Jonesy correctly pointed out, you have a typo in your code. The second textbox should be model.SubmissionDate. That is probably causing the validation error I've mentioned earlier.
Talk1:
I think this along with Stephen's comment should set him straight
Talk2:
I was able to fix the issue. Thanks a bunch walther.
Talk3:
, no problem. If I was right, you should probably mark my answer as accepted, so that other people see how you fixed it for future reference...
Talk4:
Apologies ... Done :) new to Stack overflow and MVC too .