1
You guys all right? it’s me again, I know I’m asking a lot of questions, but I’m having a few questions and I can’t find an answer, I’m wanting to capture the event of a button in Asp.net mvc using Razor, I’m with the following button:
<input type="button" value="Salvar" onclick="location.href='@Url.Action("insert")'" />
and this is my code from controller
public ActionResult insert()
{
myMetodInsert();//futuro método que ira inserir dados na base
return List();
}
The method returns another method List
that returns a view, but I noticed that he tries to access a page with the name of the method, but this is not the intention. The intention is to call a method that will include data in the database and then return the page. They could 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 merchandise. This list contains in its first element a selection field with checkbox
(worthwhile boolean
in the same).
As soon as the person marks the checkbox
, it enables editing. At the moment the person clicks the button salvage, i must capture this event, receive this modified list and persist the change in the database.
I am in doubt only in capturing the event. When I used java with JSF, just put the bean + method on the button he identified it. On Asp.net MVC there is nothing like it?
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()
{
}
}
Drinking class
public class bebida
{
//Chamadas externas
public String nome{ get; set; }
public Double Valor{ get; set; }
public Bebida()
{
}
}
From to do what I need only using the native Asp.net mvc? api or will I need to actually use other api’s?
Wouldn’t it be better to use Ajax to do what you want?
– Leonel Sanches da Silva
I agree with @Ciganomorrisonmendez , use AJAX.
– Wellington Silva Ribeiro
Change the question and place the class structure
Produto
that I make another answer more appropriate to answer your question.– Richard Dias
Question now this modified with the product and drink class
– Genisson