Are you okay? I am new, I know I am asking a lot of questions, but I am having some doubts and I can not find an answer, I am trying to capture the event of a button in asp.net mvc using razor, I am with the following button:
<input type="button" value="Salvar" onclick="location.href='@Url.Action("insert")'" />
and this is my controller code
public ActionResult insert()
{
myMetodInsert();//futuro método que ira inserir dados na base
return List();
}
The method returns another List
method that returns a view , but I noticed that it tries to access a page with the method name, but that is not the intention. The intent is to call a method that will include data in the database and then return the page. Could you help?
Edit
The question is this: I open a page with a list of goods, where the person can change only the value of the goods. This list contains in its first element a selection field with checkbox
(with value boolean
in it).
Once the person sets checkbox
, it enables editing. The moment the person clicks the save button, I must capture this event, receive this modified list, and persist the modification in the database.
I'm just in doubt about catching the event. When I used java with JSF, I just put the bean + method on the button it identified. In ASP.NET MVC do not you have something like this?
For further clarification follow the code like this:
View
@model Teste.Models.Produto
@{
Layout = null;
}
@using (Html.BeginForm("Salvar", "ListaProdutoCab", FormMethod.Post))
{
<table>
<thead>
<tr>
<th>Selecione</th>
<th>Produto</th>
<th>Valor</th>
</tr>
</thead> @foreach (var item in Model.listaBebida)
{
<tr>
<td> @Html.CheckBoxFor(modelItem => item.isEditado)</td>
<td> @Html.TextBoxFor(modelItem => item.produto, new { disabled = "disabled" }) </td>
<td> @Html.TextBoxFor(modelItem => item.valor) </td>
</tr>
}
</table>
<div id="modal">
<div id="botoes">
<button type="submit">Salvar</button>
</div>
</div>
}
My Controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Teste.DAO;
using Teste.Models;
namespace Teste.Controllers
{
public class ListaProdutoCab: Controller
{
//
// GET: /ListaProdutoCab/
ListaProdutoService service = new ListaProdutoService();
Produto produto = new Produto();
Session usuario = new Session("Genisson", 058);
List<ObjectMasterProduto> listaProduto= new List<ObjectMasterProduto>();
public ActionResult ListaProdutoCab()
{
return View();
}
public ActionResult List()
{
service.carregarListaBebida(produto.listaBebida);
return PartialView(produto);
}
[HttpPost]
public ActionResult Salvar()
{
service.Salvar(produto.listaBebida, usuario);
return RedirectToAction("List");
}
}
}
Product
public class Produto
{
//Chamadas externas
public Bebida bebida{ get; set; }
public List<Bebida> listaBebida{ get; set; }
public Produto()
{
}
}
Drink class
public class bebida
{
//Chamadas externas
public String nome{ get; set; }
public Double Valor{ get; set; }
public Bebida()
{
}
}
Does it do what I need only using native asp.net mvc api? or do I really need to use other api's?