locked
get current page title in .net core RRS feed

  • Question

  • User338455301 posted

    hi

    i want get current page title in  controller ? how to access and do it ? 

    Sunday, May 31, 2020 10:10 AM

All replies

  • User475983607 posted

    elahi1mahdi

    i want get current page title in  controller ? how to access and do it ? 

    The controller sets the title the controller does not read the title.  The standard layout template has a ViewData["Title"] that renders the title set in the controller.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>@ViewData["Title"] - MvcBasic</title>
    @{
        ViewData["Title"] = "Home Page";
    }

    Reference documentation.

    https://docs.microsoft.com/en-us/aspnet/core/mvc/views/layout?view=aspnetcore-3.1

    Sunday, May 31, 2020 12:02 PM
  • User-2054057000 posted

    hi

    i want get current page title in  controller ? how to access and do it ? 

    Just make a default ASP.NET Core web application and select MVC when creating a new app in Visual Studio. Then check the codes given on the Views. You can find how ViewBag is used to work with page titles. 

    Sunday, May 31, 2020 2:27 PM
  • User338455301 posted

    no, i have logUser_tb to create log for  any user that go to pages 
    in logUser_tb i save this property 

    User_Id , Page_Url , Date , Page_Title

    i create a action filter that save log for user 
    in action filter how can i get page title ? 

    Tuesday, June 2, 2020 4:39 AM
  • User475983607 posted

    no, i have logUser_tb to create log for  any user that go to pages 
    in logUser_tb i save this property 

    User_Id , Page_Url , Date , Page_Title

    i create a action filter that save log for user 
    in action filter how can i get page title ?

    Not possible as explained clearly above.  You need to come up with a design to store the page title in a database table.

    Tuesday, June 2, 2020 10:03 AM