Click here to Skip to main content
14,920,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys. I'm fighting with my code for some time.. I'm trying to open another view using simple button

id of button is - openbagpromotion and action of controller is OpenBagPromotion

What I saw is that after clicking a button, there is no information about it in developer mode of chrome. So propably I've wrongly use button.

<pre>@model Artemis.Models.PromoCode

@{
    ViewData["Title"] = "Wybór promocji";
}

<div class="row">
    <div class="col-xl-2">
        <img class="align-content-center" src="/Images/tarcza.png" />
    </div>
    <div class="col-xl-8">
        <div>
            <img class="mx-auto" src="/Images/podlewka_promocja_artemis.svg" />
            <h2 class="align-content-center">Teraz ustrzel NAGRODY z ARTEMIS 450 EC!</h2>
        </div>
        <div class="row">
            @if (Model.IsBagAlreadyRegistered)
            {
                <div class="col-sm-6">
                    <p>NAGRODA</p>
                    <p>ZA ZGODĘ!</p>
                    <img class="mx-auto my-auto" src="/Images/mleczko_torba.png" />
                    <p>Bawełniana torba z limitowanej serii</p>
                    <p>z rysunkiem Andrzeja Mleczki!</p>
                    <p>Już wziąłeś udział</p>
                    <p>w tej promocji!</p>
                    <p>DZIĘKUJEMY</p>
                </div>
            }
            @if (!Model.IsBagAlreadyRegistered)
            {
                <div class="col-sm-6">
                    <p>NAGRODA</p>
                    <p>ZA ZGODĘ!</p>
                    <button type="submit" class="btn-primary" id="OpenBagPromotion" name="OpenBagPromotion" asp-action="OpenBagPromotion"><img src="/Images/przejdz_dalej.svg" />WCHODZĘ</button>
                    <img class="mx-auto my-auto" src="/Images/mleczko_torba.png" />
                    <p>Bawełniana torba z limitowanej serii</p>
                    <p>z rysunkiem Andrzeja Mleczki!</p>
                </div>
            }
            <div class="col-sm-6">
                @if (Model.IsCupAndShirtAlreadyRegistered)
                {
                    <p>KUP ARTEMIS 450 EC</p>
                    <p>I ODBIERZ NAGRODĘ</p>
                    <img class="mx-auto my-auto" src="/Images/mleczko_kubek.png" />
                    <img class="mx-auto my-auto" src="/Images/mleczko_koszulka.png" />
                    <p>Bawełniana torba z limitowanej serii</p>
                    <p>z rysunkiem Andrzeja Mleczki!</p>
                    <p>Już wziąłeś udział</p>
                    <p>w tej promocji!</p>
                    <p>DZIĘKUJEMY</p>
                }
                @if (!Model.IsCupAndShirtAlreadyRegistered)
                {
                    <p>KUP ARTEMIS 450 EC</p>
                    <p>I ODBIERZ NAGRODĘ</p>
                    <button type="submit" class="btn-primary" id="OpenCupPromotion" name="OpenCupPromotion" asp-action="" " value="inp"><img src="/Images/przejdz_dalej.svg" />WCHODZĘ</button>
                    <img class="mx-auto my-auto" src="/Images/mleczko_kubek.png" />
                    <img class="mx-auto my-auto" src="/Images/mleczko_koszulka.png" />
                }
            </div>
        </div>
    </div>
    <div class="col-xl-2">
        <img class="float-right" src="/Images/womanwithabow.png" />
    </div>
</div>


<pre>        private readonly ILogger<HomeController> _logger;

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }
        
        public IActionResult CheckPromoCode(string inputPromoCode)
        {
            if (inputPromoCode == "12345678") return View("PromoPick", new PromoCode(){IsCupAndShirtAlreadyRegistered = false, IsBagAlreadyRegistered = false});
            if (inputPromoCode == "87654321") return View("PromoPick", new PromoCode() { IsCupAndShirtAlreadyRegistered = true, IsBagAlreadyRegistered = true });
            return View("Index", new PromoCode(){Exist = false});
        }

        [HttpPost]
        public IActionResult OpenBagPromotion()
        {
            return View("BagPromo");
        }


What I have tried:

I've already tried to create new controller, routing...
Posted
Comments
Richard Deeming 24-Mar-21 5:46am
   
As far as I can see, the asp-action helper only applies to <form> and <a> elements, not <button> elements.

View the source of your rendered page in your browser. Is the asp-action attribute visible on the <button>? If so, it's not being processed on the server, and you'll either need to write a custom tag helper, or switch to using an <a> element instead.
lord giv 24-Mar-21 5:50am
   
this is exactly what is rendering in code

<button type="submit" class="btn-primary" id="OpenBagPromotion" name="OpenBagPromotion" formaction="/Home/OpenBagPromotion"><img src="/Images/przejdz_dalej.svg" />WCHODZĘ</button>
lord giv 24-Mar-21 5:52am
   
OK! I've wraped whole div in tag and it's working. thanks for solution! You are the best

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



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