Hello friends,
I am new in MVC.
I have created a grid and fetch data from database into it.
For Adding record I have opened a window on button click and save data in database.
Now I am trying to validate the controls but some how it is not working.
Kindly guide me friends on this.
--------- FileBugController.cs----------
- [HttpPost]
- public ActionResult Index(FileBugModel bug)
- {
- if(ModelState.IsValid)
- {
- string connStr = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
- using (SqlConnection con = new SqlConnection(connStr))
- {
- con.Open();
- using (SqlCommand cmd = new SqlCommand("InsertFiledBug", con))
- {
- cmd.CommandType = System.Data.CommandType.StoredProcedure;
- cmd.Parameters.AddWithValue("@EmployeeId", bug.EmpId);
- cmd.Parameters.AddWithValue("@IsCritical", bug.IsCritical);
- cmd.Parameters.AddWithValue("@BugType", bug.BugType);
- cmd.Parameters.AddWithValue("@BugSummary", bug.BugSummary);
- cmd.Parameters.AddWithValue("@BugDescription", bug.BugDescription);
- cmd.ExecuteScalar();
- }
- }
- return RedirectToAction("Close");
-
- }
- else
- {
- return View(bug);
- }
- }
---------FileBugModel.cs---------
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Web;
- namespace Test_BugTrak.Models
- {
- public class FileBugModel
- {
- public int EmpId { get; set; }
- public string EmployeeName { get; set; }
- public string EmpFirstName { get; set; }
- public string EmpLastName { get; set; }
- public List Bname { get; set; }
- public string IsCritical { get; set; }
- public string BugType { get; set; }
- [Required(ErrorMessage = "Please Enter Bug Summary")]
- public string BugSummary { get; set; }
- public string BugDescription { get; set; }
- }
- }
-------FileNewBug.cshtml---------
- @model Test_BugTrak.Models.FileBugModel
- @{
- Layout = null;
- }
- @**@
- .error{
- color:red;
- }
- @using (Html.BeginForm("Index", "FileBug", FormMethod.Post))
- {
-
- @Html.Label("Critical")
- @Html.RadioButtonFor(m => m.IsCritical, "Y", new { value = "Y"})
- @Html.RadioButtonFor(m => m.IsCritical, "N", new { value = "N"})
- @Html.Label("Bug Type *")
- @Html.RadioButtonFor(m => m.BugType, "D", new { value = "D"})
- @Html.RadioButtonFor(m => m.BugType, "F", new { value = "F"})
- @Html.Label("Assign To")
- @Html.DropDownListFor(m => m.EmpId, new SelectList(Model.Bname, "EmpId", "EmployeeName"), "Select User")
- @Html.Label("Summary *")
- @Html.TextBoxFor(m => m.BugSummary)
- @Html.ValidationMessageFor(m => m.BugSummary,"",new {@class="error" })
- @Html.Label("Description *")
- @Html.TextAreaFor(m => m.BugDescription)
- }
Following error occur after ModelState.IsValid check in else part.
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/FileBug/Index.aspx
~/Views/FileBug/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/FileBug/Index.cshtml
~/Views/FileBug/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
Image of my Solution Explorer. Maybe I have mistaken here. Kindly help me out.
This Is screenshot of my Solution Explorer