0

I'm using ASP.NET Core 6, and I'm wondering if I can send data from one HTML view to the same controller but to two different methods using a single submit button? I'm using a single ASP form, and so far, I haven't found a way to do it without using JavaScript

Thanks Sasa'

namespace ACS.Controllers
{
    public class MAWBController : Controller
    {
        private ProductContext _productContext;
    
        public MAWBController (ProductContext productContext)
        {
            _productContext = productContext;
        }
    
        public static List<Models.Shipment> listaMAWB = new List<Shipment>();
    
        [HttpGet]
        public IActionResult InsertMAWB()
        {
            return View();
        }
    
        [HttpPost]
        public IActionResult InsertMAWB(Shipment model)
        {
            if (ModelState.IsValid)
            {
                _productContext.Shipments.Add(model);
                _productContext.SaveChanges();
                    
                return RedirectToAction("Manipulacija");
            }
            else
            {
                return View(model);
            }
        }
    
        public IActionResult Manipulacija()
        {
            return View();
        }
    
        public IActionResult ShowListMAWB()
        {
            return View(listaMAWB);
        }
    
        public IActionResult IzracunTotalaPdv(decimal Manipulacija, decimal DgHandling,decimal PDV)
        {
            Shipment shipment = new Shipment();
    
            decimal UkupnoSPDV = shipment.UkupnoSPDV(Manipulacija, DgHandling, PDV);
    
            ViewBag.UkupnoSPDV = UkupnoSPDV;
    
            return View(shipment);
        }
    }
}

View:

@model ACS.Models.Shipment

<form asp-action="InsertMAWB" method="post">
    <label asp-for="ArrivalDate"></label>
        <input asp-for="ArrivalDate" />
        <span asp-validation-for="ArrivalDate" class="text-danger"></span>
        </br>
        </br>
        <label asp-for="MAWB"></label>
        <input asp-for="MAWB" />
        <span asp-validation-for="MAWB" class="text-danger">
        </span>
    
        </br>
        </br>
    
        <label asp-for="GrossWeight"></label>
        <input asp-for="GrossWeight" />
        <span asp-validation-for="GrossWeight" class="text-danger">
        </span>
        
        </br>
        </br>
       
        <label asp-for="IsDG"></label>
        <input asp-for="IsDG" />
        <span asp-validation-for="IsDG" class="text-danger">
        </span>
       
        </br>
        </br>
    
        <div>
            <label for="Manipulacija">Manipulacija:</label>
            <input asp-for="Manipulacija" />
            <span asp-validation-for="Manipulacija" class="text-danger"></span>
        </div>
        <div>
            <label for="DgHandling">DgHandling:</label>
            <input asp-for="DgHandling" />
            <span asp-validation-for="DgHandling" class="text-danger"></span>
        </div>
        <div>
            <label for="PDV">PDV:</label>
            <input asp-for="PDV" />
            <span asp-validation-for="PDV" class="text-danger"></span>
        </div>
    
        <button type="submit">Pošalji</button>
    </form>
</div>
2
  • ` send data from one HTML view to the same controller but to two different methods using a single submit button` -> Can when know when it will be sumbit to method one and when it will be sumbit to method two? If it requires a judgement, maybe we have to use js code to control it. Commented Jun 7, 2024 at 13:38
  • 1
    hi yes looks like that I need to use ajax to solve this Commented Jun 12, 2024 at 11:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.