d0812
d0812

Reputation: 5

how to handle events in MVC 4 (ASPX)

I am very new in MVC ,created application in VS12 MVC4 with ASPX selection.I have design master page. created one controller and then view from controller->add view with nested created master page. My view code is like below(show only required code)

<asp:Table runat ="server"  HorizontalAlign ="Center" >
        <asp:TableRow >
            <asp:TableCell >                    
                <dx:ASPxButton ID="btnlogin" runat="server" Text="Login"></dx:ASPxButton>
            </asp:TableCell>
             <asp:TableCell >
                <dx:ASPxButton ID="btnCancel" runat="server" Text="Cancel"></dx:ASPxButton>
            </asp:TableCell>
        </asp:TableRow>
    </asp:Table>

how to redirect to another page after login successfully?

Upvotes: 0

Views: 84

Answers (1)

Alex Belets
Alex Belets

Reputation: 406

d0812!

Actually, in your home controller, in method Index (which should call firstly for client by default) something like this will be:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

It means the following for your application: If client calls http(s)://yourapp/ or http(s)://yourapp/home, this method will invokes. ActionResult is a server response in general.

Next, client will recieve file with name Index from folder /(root)/Views/Home/.

But you can also do this:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View("myViewName");
    }
}

and then your client will come to the file with a name myViewName in the same folder.

Thus you can check for identity of your client:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        if (User.Identity.IsAuthenticated)
        {
            return View("myViewName");
        }
        return View();
    }
}

Next, you cant implement POST method for client authorization with the attribute

    [HttpPost] 
    public ActionResult Login(LoginModel model)
        {
             //TODO: implement
             //note: you can redirect the user here 
             //as described above
        }

where LoginModel is just serializable class:

public class LoginModel
{
    public string Login { get; set; }
    public string Password { get; set; }
}

or start using something like owin2

I hope, it will help you.

Upvotes: 1

Related Questions