Multiple Views in a single controller with different actions

Last Reply 6 days ago By dharmendr

Posted 7 days ago

I am having a report page whose controller is having two different actions, one link directs to one action and other link directs to other action. but i am not able to do that, kindly check the issue

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>

    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
    @Scripts.Render("~/bundles/modernizr")
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
    
    <style>
        * {
            font-family: 'Nunito', sans-serif;
            font-style: normal;
            font-weight: 400;
        }
    </style>
</head>

<body>
    <div class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
        <div class="container">
            <div class="navbar-header">

                @Html.ActionLink("CPSE Monitoring and Performance", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="collapse navbar-collapse" id="navbar1">
                <ul class="navbar-nav w-100">

                    <li class="nav-item dropdown ml-auto">
                        <a href="#" class="nav-link dropdown-toggle" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            <label>Welcome @Session["UserID"].ToString()</label>
                        </a>
                        <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink">
                            <a class="dropdown-item" href="@Url.Action("Logout","LandDetail")">Logout</a>

                        </div>
                    </li>
                    <li class="nav-item dropdown ml-auto">
                        <a href="#" class="nav-link dropdown-toggle" id="navbarDropdownMenuLink2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            Report
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink2">
                            <a class="dropdown-item" href="@Url.Action("Index","Reports")">Land</a>
                            <a class="dropdown-item" href="@Url.Action("LoadDataMining","Reports")">Mining Land 1</a>
                        </div>
                       
                    </li>

                </ul>
            </div>
        </div>
    </div>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - Created By NIC-DHI</p>
        </footer>
    </div>
    
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("Scripts",false)
</body>
</html>

 

namespace CPSEDetail.Controllers
{
    public class ReportsController : Controller
    {
        public class SessionAuthorizeAttribute : AuthorizeAttribute
        {
            protected override bool AuthorizeCore(HttpContextBase httpContext)
            {
                return httpContext.Session["UserID"] != null;
            }

            protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
            {
                filterContext.Result = new RedirectResult("/Home/Index");
                //filterContext.Result = new RedirectResult("redirect");
            }
        }
        // GET: Reports
        [SessionAuthorize]
        public ActionResult Index()
        {
            return View();
        }

        [SessionAuthorize]
        public ActionResult LoadData()
        {
            string st = Session["UserID"].ToString();
            using (CPSEdbEntities1 db = new CPSEdbEntities1())
            {
                var CpseDetails = db.CPSE_Landdetails.Where(c => c.Section_Name == st).ToList<CPSE_Landdetails>();
                return Json(new { data = CpseDetails }, JsonRequestBehavior.AllowGet);
            }
            
        }
        [SessionAuthorize]
        public ActionResult LoadDataMining()
        {
            string st = Session["UserID"].ToString();
            using (CPSEdbEntities1 db = new CPSEdbEntities1())
            {
                var CpseDetails = db.CPSE_Landdetails.Where(c => c.Section_Name == st).ToList<CPSE_Landdetails>();
                return Json(new { data = CpseDetails }, JsonRequestBehavior.AllowGet);
            }
           

        }

 

@{
    //Layout = null;
    Layout = "~/Views/Shared/_LayoutPage1.cshtml";
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>LoadDataMining</title>
</head>
<body>
    <div class="container" style="margin-top:80px">


        <table id="LandResource" class="ui celled table">
            <thead>
                <tr>
                    <th>S.No</th>
                    <th>CPSE Name</th>
                    <th>State</th>
                    <th>Unit</th>
                    <th>Status</th>
                    <th>Land FreeHold Mutated</th>
                    <th>Land FreeHold Non-Mutated</th>
                    <th>Land Lease Hold</th>
                    <th>Land Total</th>
                </tr>
            </thead>

        </table>
    </div>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.1/semantic.min.css" />
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.semanticui.min.css" />
    @section Scripts{
        <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
        <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>

        <script src="https://cdn.datatables.net/1.10.19/js/dataTables.semanticui.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.1/semantic.min.js"></script>


        <script>

            $(document).ready(function () {


                $('#LandResource').DataTable({
                    "ajax": {
                        "url": '@Url.Action("LoadDataMining", "Reports")',
                        "type": "GET",
                        "dataType": "json"
                    },

                    "fnRowCallback": function (nRow, aData, iDisplayIndex) {
                        var oSettings = this.fnSettings();
                        $("td:first", nRow).html(oSettings._iDisplayStart + iDisplayIndex + 1);
                        return nRow;
                    },

                    "columns": [
                        { "data": null, "autoWidth": true },
                        { "data": "MiningLease1_FreeHold", "autoWidth": true },
                        { "data": "MiningLease1_LeaseHold", "autoWidth": true },
                        { "data": "MiningLease1_DateOfExecution", "autoWidth": true },
                        { "data": "MiningLease1_Validupto", "autoWidth": true },
                        { "data": "MiningLease1_MIneralAssessed", "autoWidth": true },
                        { "data": "MiningLease1_MineralReserves", "autoWidth": true },
                        { "data": "MiningLease1_MinedOut", "autoWidth": true },
                        { "data": "MiningLease1_Balance_reserves", "autoWidth": true },



                    ]
                });
            });

        </script>
    }
</body>
</html>

 

@{
    //Layout = null;
    Layout = "~/Views/Shared/_LayoutPage1.cshtml";
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
  
</head>
<body>
    <div class="container" style="margin-top:80px">


        <table id="LandResource" class="ui celled table">
            <thead>
                <tr>
                    <th>S.No</th>
                    <th>CPSE Name</th>
                    <th>State</th>
                    <th>Unit</th>
                    <th>Status</th>
                    <th>Land FreeHold Mutated</th>
                    <th>Land FreeHold Non-Mutated</th>
                    <th>Land Lease Hold</th>
                    <th>Land Total</th>
                </tr>
            </thead>

        </table>
    </div>

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.1/semantic.min.css" />
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.semanticui.min.css" />
    @section Scripts{
        <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
        <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>

        <script src="https://cdn.datatables.net/1.10.19/js/dataTables.semanticui.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.1/semantic.min.js"></script>


        <script>

            $(document).ready(function () {


                $('#LandResource').DataTable({
                    "ajax": {
                        "url": '@Url.Action("LoadData","Reports")',
                        "type": "GET",
                        "dataType": "json"
                    },

                    "fnRowCallback": function (nRow, aData, iDisplayIndex) {
                        var oSettings = this.fnSettings();
                        $("td:first", nRow).html(oSettings._iDisplayStart + iDisplayIndex + 1);
                        return nRow;
                    },

                    "columns": [
                        { "data": null, "autoWidth": true },
                        { "data": "CPSE_id", "autoWidth": true },
                        { "data": "CPSE_StateName", "autoWidth": true },
                        { "data": "CPSE_Unit_Name", "autoWidth": true },
                        { "data": "Land_Status", "autoWidth": true },
                        { "data": "LandFreeHold_Mutated", "autoWidth": true },
                        { "data": "LandFreeHold_NonMutated", "autoWidth": true },
                        { "data": "LandLeaseHold", "autoWidth": true },
                        { "data": "LandTotal", "autoWidth": true },



                    ]
                });
            });

        </script>
    }
</body>
</html>

 

You are viewing reply posted by: dharmendr 6 days ago.
Posted 6 days ago

Hi sunnyk21,

Not getting you clearly.

Do you want to return two Json result from both the ActionResult ?

Also your both the ActionResult returns same result. So whay you are creating two ActionResult ?

Please explain in details.