Strange Issue after adding Login screen

Oct 14, 2014 at 7:10 AM
Edited Oct 14, 2014 at 7:11 AM
I am facing very strange issue in my current project. I download the default sample and now i have added login screen before it actually calls up Index page. it works fine until i click on page numbers for Grid. so lets say i have total 10 pages for the current grid records, when i click on "2" it shows up me login screen instead of going to second page. when debug it i see it calls up Grid() method in Home control each time when i click on page.
I also change my "routeconfig.cs" to call "Login" page instead of Index.

Home Controller

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web.Mvc;

namespace GridMvc.Site.Controllers
{
    public class HomeController : ApplicationController
    {
        public ActionResult Index()
        {
            ViewBag.ActiveMenuTitle = "Demo";
            return View();
        }

        public ActionResult Grid()
        {
            wmas_subsEntities entitymodel = new wmas_subsEntities();
            
            List<GridMvc.Models.Logging> Logs = new List<Models.Logging>();                       

            foreach(var item in entitymodel.Loggings.ToList())
            {
                Logs.Add(new Models.Logging()
                {
                    Date = item.DateTime.Value,
                    Description = item.Description,
                    ID = item.ID,
                    Reference = item.Reference,
                    Response = item.Response,
                    Time = String.Format("{0:hh:mm}", item.DateTime),                    
                    Type = item.Type
                });
            }

            return PartialView("_OrdersGrid", Logs.OrderByDescending(p => p.ID));            
        }

        [HttpPost]
        public JsonResult GetTypes()
        {
            List<string> types = new List<string>();
            
            types.Add("Activity");
            
            types.Add("Transaction");

            return Json(new { Items = types });
        }

        public ActionResult Login()
        {            
            return View();
        }

        [HttpPost]
        public ActionResult Login(FormCollection form)
        {
            if (ModelState.IsValid)
            {
                if (AuthorizeUser(form["txtuserId"].ToString(), form["txtpass"].ToString()))
                {
                    return View("Index");
                }
                else
                {
                    ModelState.AddModelError("", "Email or Password Incorrect.");
                }
            }

            return View();
        }

        private bool AuthorizeUser(string emailid, string pass)
        {
            bool flag = false;

            wmas_subsEntities wcmsContext = new wmas_subsEntities();

            var userX = from p in wcmsContext.WCMSUsers where p.userID == emailid && p.PasswordConfirm == pass select p;
            if (userX.ToList().Count > 0)
            {
                flag = true;
            }
            else
            {
                flag = false;
            }

            return flag;
        }
    }
}

Login.cshtml

@{
    Layout = null;
}

 
@using (Html.BeginForm("Login", "Home", FormMethod.Post))
  { 
    <div class="fontStyle">
        <center>
            <table style="margin-top: 100px;margin-left:150px;font-family:Calibri;">
                <tr>
                    <td colspan="2">
                        <div style="margin-left:130px"> 
                            <img src= "@Url.Content("/Content/Multi_purpose.png")" alt="Image" style="height:100px;width:100px" />                            
                        </div>
                    </td>
                </tr>
                <tr style="height:30px">
                    <td>
                        User:
                    </td>
                    <td style="width:200px" align="right">
                        <input type="text" name="txtuserId" />
                    </td>
                </tr>
                <tr style="height:30px">
                    <td>
                        Password:
                    </td>
                    <td align="right">
                        <input type="password" name="txtpass" />
                    </td>
                </tr>
                <tr style="height:30px">
                    <td colspan="2" align="center">
                        <input type="submit" value="Sign In" />
                    </td>
                </tr>
                    
                @Html.ValidationSummary(true)
            </table>
        </center>
    </div>
    }        
    </div>
</body>
</html>

Index.cshtml

@{
    ViewBag.Title = "Home Page";
}

<div class="row">
    <div class="col-md-12">
        <h1>Logs administration</h1>
        <p>
            Please select column filter to filter data
            
        </p>
    </div>
</div>

<div class="row">
    <div class="col-md-3 col-md-push-9">
        <h4>
            
        </h4>
        <div id="order-content">
            <p class="muted">
                
            </p>
        </div>
    </div>
    <div class="col-md-9 col-md-pull-3">
        @Html.Action("Grid") @* configure grid in a partial view *@
    </div>
</div>
<script>
    $(function () {
        pageGrids.ordersGrid.addFilterWidget(new TypeWidget());
        pageGrids.ordersGrid.addFilterWidget(new TimeWidget());
    });
</script>

RouteConfig

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace GridMvc.Site
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Login", id = UrlParameter.Optional }
            );
        }
    }
}

_OrdersGrid.cshtml

@using GridMvc.Html
@using GridMvc.Sorting
@model IEnumerable<GridMvc.Models.Logging>

@Html.Grid(Model).Named("ordersGrid").Columns(columns =>
    {
        /* Adding "OrderID" column: */

        columns.Add(o => o.ID)
               .Titled("Number")
               .SetWidth(100);
        columns.Add(o => o.Date, "Date")
                .Titled("Date")
                .SortInitialDirection(GridSortDirection.Descending)
                .Format("{0:dd/MM/yyyy}")
                .SetWidth(110);
        columns.Add(o => o.Time, "Time")
                .Titled("Time")                
                .SetWidth(110);                                               
        columns.Add(o => o.Type)
               .Titled("Type")
               .SetWidth(150)
               .ThenSortByDescending(o => o.ID)
               .SetFilterWidgetType("TypeFilterWidget");
        columns.Add(o => o.Description)
               .Titled("Description")
               .SetWidth(250);
        columns.Add(o => o.Reference)
                .Titled("Reference")
                .SetWidth(150)
                .Css("hidden-xs"); //hide on phones
        columns.Add(o => o.Response)
                .Titled("Response")
                .SetWidth(150)
                .Css("hidden-xs"); //hide on phones        
                

    }).WithPaging(15).Sortable().Filterable().WithMultipleFilters()

Oct 14, 2014 at 9:39 AM
Edited Oct 14, 2014 at 9:40 AM
Resolved ! I created separate controller for login and it worked.