Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a View Component on .net Core 5 with MVC:

@using NasimSys_V12.ControlPanel.Class.User;
@using NasimSys_V12.Resources;
@using Microsoft.Extensions.Localization;
@using NasimSys_V12.ControlPanel.Class.Utility;

@model UserC

@inject IStringLocalizer<SharedResourceC> SharedLocalizer;

@{
    var objCurrentUserC = @Model;
    PublicC objPublicC = new PublicC();
}

<form asp-controller="ActiveUserView" asp-action="Logout" method="post">
     <button type="submit">Click here to Logout</button>
</form>


And I made a controller named ActiveUserViewController for this component:

using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NasimSys_V12.ControlPanel.Class.User;

namespace NasimSys_V12.ControlPanel.Components.User.ActiveUser
{
    [ViewComponent(Name = "ActiveUserViewComponent")]
    public class ActiveUserViewController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }


        //==================================================================
        [HttpPost]
        public IActionResult Logout()
        {
            return View();
        }
        //==================================================================


        //==================================================================
        public async Task<IActionResult> InvokeAsync(
            UserC objcurrentUserC_par,
            string ActiveUserViewName_par)
        {
            return await Task.Run(() =>
            {
                return View(this.GetActiveUserViewName(ActiveUserViewName_par)
                , objcurrentUserC_par);
            });
        }
        //==================================================================

        /// <summary>
        ///
        /// </summary>
        /// <param name="value_par">Set Empty or 'Default' if you wanna get default view </param>
        /// <returns></returns>
        public string GetActiveUserViewName(string value_par)
        {
            string result = string.Empty;

            if (value_par == "")
            {
                result = "";
            }
            // else if value == 'Default' || anything else
            else
            {
                result = "~/ControlPanel/Components/User/ActiveUser/ActiveUserInHeader.cshtml";
            }

            return result;
        }
        //==================================================================

    }
}



When I clicked on :
<button type="submit">Click here to Logout</button>

It doesn't run
asp-action="Logout"


What I have tried:

I searched on google and changed form properties but couldn't find any solution.
could anyone help me?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900