Fetching data from DB by clicking on TAB in MVC.
Hi i'm doing a project in MVC.I have to create a TAB .I had named that TAB as "ADMIN".So,if i click on that ADMIN TAB ,i have to fetch data from DB in GridView.I known how to do in ASP.NET ,But i'm not able to do in MVC.Can u pls help me out.
Harsha EadaraPosted Jul 20, 2017, 1:23 AM
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MySql.Data.MySqlClient;
using System.Data;
using System.Data.SqlClient;
using Link.Models;
namespace Link.Controllers
{
public class HomeController : Controller
{
public ActionResult Insert()
{
return View();
}
[HttpGet]
public ActionResult Admin(string ReleaseID, string Release_Name, DateTime Scope_Lock_Date, DateTime Release_Date, string Segment, string Query, string Status)
{
MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=perfautomationdb;password=Password@1");
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM tfsperfqueue",con);
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ReleaseID", ReleaseID != null ? Convert.ToInt32(ReleaseID) : 0);
cmd.Parameters.AddWithValue("@Release_Name", Release_Name);
cmd.Parameters.AddWithValue("@Scope_Lock_Date", Scope_Lock_Date );
cmd.Parameters.AddWithValue("@Release_Date", Release_Date );
cmd.Parameters.AddWithValue("@Segment", Segment);
cmd.Parameters.AddWithValue("@Query", Query);
cmd.Parameters.AddWithValue("@Status", Status != null ? Convert.ToInt32(Status) : 0);
con.Close();
RedirectToAction("Insert");
return View();
}
}
}
@{
ViewBag.Title = "Admin";
Layout = "";
}
Admin
@Model.ReleaseID
@Model.Release_Name
@Model.Scope_Lock_Date
@Model.Release_Date
@Model.Segment
@Model.Query
@Model.Status
{
$(document).ready(function () {
//function will be called on button click having id btnsave
{
var frmdata = {
ReleaseId: $("#txtReleaseId").val(), //Reading text box values using Jquery
Release_Name: $("#txtRelease_Name").val(),
Scope_Lock_Date: $("#txtScope_Lock_Date").val(),
Release_Date: $("#txtReleaseDate").val(),
Segment: $("#txtSegment").val(),
Query: $("#txtQuery").val(),
Status: $("#txtStatus").val()
};
$.ajax({
url: '@Url.Action("Home","Admin")', // Controller/View
//method: 'Post',
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function () {
//window.location.href = '/Home/Insert';
error: function (error) {
alert(error)
}
});
} });
});
Release_Name
Scope_Lock_Date
Release_Date
Segment
Query
Parameter name: parameters Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: The parameters dictionary contains a null entry for parameter 'Scope_Lock_Date' of non-nullable type 'System.DateTime' for method 'System.Web.Mvc.ActionResult Admin(System.String, System.String, System.DateTime, System.DateTime, System.String, System.String, System.String)' in 'Link.Controllers.HomeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.Ramesh SinghPosted Jul 19, 2017, 8:31 AM
Harsha EadaraPosted Jul 19, 2017, 7:09 AM
@{
ViewBag.Title = "Admin";
Layout = "";
}
Admin
@Model.ReleaseID
@Model.Release_Name
@Model.Scope_Lock_Date
@Model.Release_Date
@Model.Segment
@Model.Query
@Model.Status
$(document).ready(function () {
//function will be called on button click having id btnsave
$("#btnst").click(function(){
var frmdata = {
ReleaseId: $("#txtReleaseId").val(), //Reading text box values using Jquery
Release_Name: $("#txtRelease_Name").val(),
Scope_Lock_Date: $("#txtScope_Lock_Date").val(),
Release_Date: $("#txtReleaseDate").val(),
Segment: $("#txtSegment").val(),
Query: $("#txtQuery").val(),
Status: $("#txtStatus").val()
};
$.ajax({
url: '@Url.Action("Admin","Home")', // Controller/View
//method: 'Post',
data: frmdata,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function () {
//window.location.href = '/Home/Insert';
error: function (error) {
alert(error)
}
});
});
});
Ramesh SinghPosted Jul 19, 2017, 6:28 AM
Harsha EadaraPosted Jul 19, 2017, 2:20 AM
Parameter name: parameters Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: The parameters dictionary contains a null entry for parameter 'ReleaseID' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Admin(Int32, System.String, System.DateTime, System.DateTime, System.String, System.String, Int32)' in 'Link.Controllers.HomeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
Harish SupekarPosted Jul 17, 2017, 6:47 AM