asp.net mvc 4 - How to link from View in Area to the root controller? -
i'm new mvc
, still learning ins , outs converting .net
app mvc
.
i have trouble linking action
in controller
page inside of "area"
section.
i created areas
, still have default route set up.
the area
has following structure:
area - admin - controller usercontroller.cs -model -views user index.cshtml
index.cshtml
has link should call "index"
action in accountcontroller
open "default"
view:
<div class="pagenavigator">@html.actionlink("main menu", "index", new { area = "", controller="account" })</div>
the default structure of application following:
- controller accountcontroller.cs - views - account default.cshtml login.cshtml
my default structure has controller folder has controller login (default) action set in routeconfig.cs
:
routes.maproute( name: "default", url: "{controller}/{action}/{id}", defaults: new { controller = "account", action = "login", id = urlparameter.optional } );
here account controller
:
public class accountcontroller : controller { public actionresult login(string returnurl) { stringbuilder sb = new stringbuilder(); sb.append("web security administration portal<br/><br/>"); viewbag.returnurl = returnurl; viewbag.message = sb.tostring(); return view(); } public actionresult index() { return view("default"); } public actionresult login(loginmodel model) { if (modelstate.isvalid) { bool authenticated = security.authenticatelanuser(model.username, model.password); if (!authenticated) { session["authenticated"] = false; system.text.stringbuilder errormsg = new system.text.stringbuilder(); errormsg.append("invalid login/password entered."); errormsg.append("we not able authenticate in in active directory based on information entered, "); errormsg.append("but recorded attempt audit purposes."); modelstate.addmodelerror("", errormsg.tostring()); return view(model); } else { return view("default"); } } modelstate.addmodelerror("", "the user name or password provided incorrect."); return view(model); } }
what should if need link "default"
view defined under default application route, index.cshtml
defined under area
, when click link, "accountcontroller"
gets called correct "index"
action?
in short, need find out way link "area" section controller's action in default application section, correct action gets called, not specified in default route mapping right now, link broken.
when view link in source, see following: <a href="/account/index">
, when click on link, i'm getting error saying: resource cannot found requested url: /login.aspx
here adminarearegistration:
public override void registerarea(arearegistrationcontext context) { context.maproute( "admin_default", "admin/{controller}/{action}/{id}", new { action = "index", id = urlparameter.optional } ); }
Comments
Post a Comment