0

I have a submit button in index.cshtml page and when i click that button i need to go in another ActionResult server method.But it's not working.(not hitting to the server side method)

Html

@model IEnumerable<AAB.Domain.Items>
<!-- Featured Products -->
<div class="card-deck card-deck-product mt-3 mb-2 mb-sm-0">
    @foreach (var item in Model)
    {
        <div class="card card-product" id="@item.ItemId">
            <div class="card-body">
                <button class="wishlist atw-demo " title="Added to wishlist"><i data-feather="heart"></i></button>
                <a href="#"><img class="card-img-top" src="@item.ImageUrl" alt="Card image cap"></a>
                <a href="#" class="card-title">@item.ItemName</a>
                <div class="price"><span class="h5">Rs:@item.ItemPrice</span></div>
            </div>

            <div class="card-footer">

                <input type="submit" class="btn btn-sm" id="@item.ItemId" value="Add to Cart" href="@Url.Action("AddNewItems","Home",new { ItemId=item.ItemId})"/>
            </div>
        </div>

    }
</div>

Server side

[HttpPost]
    public ActionResult AddNewItems(int ItemId)
    {
        // Some code here.
        return PartialView("_PopCart", ItemId);
    }
TechGuy
  • 4,298
  • 15
  • 56
  • 87
  • Do you have a form? `using (@Html.BeginForm("AddNewItems", "Home", FormMethod.Post)) {` then ways to handle multiple submit buttons https://stackoverflow.com/q/442704/125981 or https://stackoverflow.com/q/36555265/125981 it's not the button but the form that defines this normally. When you submit via "enter" what button would you expect for example? You may want a hidden input to hold the value and manage it via Javascript etc. You could define multiple forms in your loop also...but which via "enter" key again...focus perhaps? Also see https://stackoverflow.com/a/16744311/125981 – Mark Schultheiss Dec 31 '18 at 15:55

1 Answers1

0

Surround your button with a tag.

<a href="@Url.Action("AddNewItems","Home",new { ItemId=item.ItemId})">
<input type="submit" class="btn btn-sm" id="@item.ItemId" value="Add to Cart" />
</a>
Mushthaqu
  • 34
  • 1
  • 3