locked
Are function return string can used when routing after controller or not controller/action ? RRS feed

  • Question

  • User696604810 posted

    PROBLEM

    can I use string function inside controller and replace action or not on asp.net core 2.1 ?


    on asp.net core 2.1 when link to any web application i use default route
    controller/action
    can i use function return string as function ShowText() after controller
    meaning employee/ShowText or must use Action Result ?
    and when route to link employee/ShowText 
    are this route will work ?

    What I have tried:

    employeecontroller
    public string ShowText()
    {
    string show = "welcom ";
    return show ;
    }
    Thursday, July 11, 2019 7:49 AM

Answers

  • User696604810 posted

    THANK YOU FOR reply

    when make link controller/stringfunction this will work or not 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 11, 2019 8:19 AM

All replies

  • User753101303 posted

    Hi,

    And what happens ? How do you call that ? Have a look at https://docs.microsoft.com/en-us/aspnet/core/web-api/action-return-types?view=aspnetcore-2.2

    Maybe you are trying to do something such as a view component ? See https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-components?view=aspnetcore-2.2

    If it doesn't help explain perhaps regardless of any technical consideration what you are trying to do. For now my understanding is that your utimate goal is to render a specific snippet of markup inside pages(s) ? BTW if found on most if not all pages you could also have a look at "layout pages".

    Thursday, July 11, 2019 8:14 AM
  • User696604810 posted

    THANK YOU FOR reply

    when make link controller/stringfunction this will work or not 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 11, 2019 8:19 AM
  • User753101303 posted

    If sending an http request to this controller/action you'll get this text as a response. What if you just try in your browser using <site>/Employee/ShowText ? is this what you mean by "make link"?

    Still it seems to be really overkill to me if your intent is really to get some small text even all along even with a user name.

    Thursday, July 11, 2019 8:52 AM