Skip to content

toosean/AspNetMvcUrlHelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AspNetMvcUrlHelper

using symbol not string to build url route.

#How

public class SomeController : Controller
{
    public ActionResult Index(){
        return Content("Index");
    }
    
    public ActionResult Search(string word){
      return Content("Search");
    }
}

// /Some/Index
var url = Url.Action<SomeController>(p=>p.Index());

// /Some/Search?word=sean
var word = "sean";
var url = Url.Action<SomeController>(p=>p.Search(word));

#HtmlHelper

//before
Html.Action("Search","Some",new {word="sean"});
//after
Html.Action<SomeController>(p=>p.Search("sean"));

//before
Html.RenderAction("Search","Some",new {word="sean"});
//after
Html.RenderAction<SomeController>(p=>p.Search("sean"));

#UrlHelper

//before
Url.Action("Search","Some",new {word="sean"});
//after
Url.Action<SomeController>(p=>p.Search("sean"));

#Code in action

//new method (same as Url.Action)
this.ActionUrl<SomeController>(p=>p.Search("sean"));

//before
this.RedirectToAction("Search","Some",new {word="sean"});
//after
this.RedirectToAction<SomeController>(p=>p.Search("sean"));

//if just redirect action in same controller 
this.RedirectToAction(p=>p.Search("sean"));

About

using symbol not string to build url route.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages