简体   繁体   中英

how to override a action method in the controller with same name and signature.?

    public ActionResult ListRss(int languageId)
    {
        return View();
    }

    public ActionResult ListRss(int languageId)
    {

        return View() ;
    }

I have this two method, Here I just want to override first method with the second one. My goal is to just keep the first method unused for the reference and make the another method.

Is it Possible any way..?

You can't have methods with the same name and signature in one class. You have to rename one of them if the signature is the same.

If you don't want to use the first method, maybe you should just comment it out and keep it as reference in comments.

as names of the actions are very strongly binded with the request params and routing mechanism.. you simply can not do much as far as i know.. ofcourse you can differentiate them by attributes of which type of request is going to made...

[HttpPost]
public ActionResult ListRss(int languageId)
{
    return View();
}

[HttpGet] // or any other http types
public ActionResult ListRss(int languageId)
{

    return View() ;
}

other way which is more complicated is to create own controller factory..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM