asp.net mvc - MVC One controller many Index view -


i've searched many topics couldn't find answer question. i'm using mvc 6.

i have following structure:

> controllers   > accountcontroller > views   > account       index.cshtml     > myreviews         index.cshtml 

the accountcontroller looks like:

// // get: /account/index [allowanonymous] //temp [httpget] public iactionresult index() {     return view(); } // // get: /account/myreviews/index [allowanonymous] //temp [httpget] [route("/account/myreviews/")] public iactionresult index() {     return view(); } 

if has different name , placed in separate controller working fine:

public class myreviewscontroller : controller {     //     // get: /account/myreviews/default     [allowanonymous]     [httpget]     [route("/account/myreviews/")]     public iactionresult default()     {         return view();     } } 

i want have myreviews working on using accountcontroller:

http://my.domain/account/myreviews/ 

first of must enable attribute routing if want multiple index actions inside 1 controller. enable add following routeconfig.cs

 routes.mapmvcattributeroutes(); 

after rename myreviews\index.cshtml myreviewsindex.cshtml inside account folder (delete myreviews folder). looks following

> controllers   > accountcontroller > views   > account       index.cshtml       myreviewsindex.cshtml  // // get: /account/index [allowanonymous] //temp [httpget] public iactionresult index() {     return view(); } // // get: /account/myreviews/index [allowanonymous] //temp [httpget] [route("account/myreviews")] public iactionresult myreviewsindex() {     return view(); } 

now can acces 2 actions by:

http://localhost/account  http://localhost/account/myreviews 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -