0
I need to open the create view by clicking a button, how to do this by Jquery?
Knob
<div class="col-md-3">
<button id="btnNovo" class="btn btn-info form-control" style="width: 200px"> Novo </button>
</div>
Script
<script>
jQuery(document).ready(function () {
$('#btnNovo').click(function () {
});
$("#filtro").on("keyup", function () {
var value = $(this).val().toLowerCase();
$("#myTable > tr").each(function () {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
</script>
Action
// GET: Pais/Create
public ActionResult Create()
{
ViewBag.cadastradoComSucesso = false;
ViewBag.cadastroComErro = false;
PaisModel paisModel = new PaisModel();
paisModel.Ativo = true;
paisModel.DataCadastro = DateTime.Now;
paisModel.UsuarioCadastro = "USUARIO CADASTRO";
return View(paisModel);
}
If you want to "open" the full view, why not make a normal request from the browser? Why use jQuery?
– Jéf Bueno
What would that form look like @LINQ?
– Nicola Bogar
Put a href on Button ?
– Nicola Bogar
Create a link and call the URL that will trigger the action and return to view.
– Jéf Bueno
Button may not have href, but that’s the way. Use a tag
a
and put the href– Jéf Bueno
Is that correct? Because the visual studio gives a warning that you can’t have a button inside the tah <a>
– Nicola Bogar
<a href="@Url.Action("Create","Parents")"> <button id="btnNovo" type="button" class="btn btn-info"> New </button> </a>
– Nicola Bogar
Can’t have a button (
<button>
) inside an anchor (<a>
).– Jéf Bueno
@LINQ, could you tell me the best way, if you could set an example I would be very grateful.
– Nicola Bogar
It’s that I don’t know what you want to do, your question doesn’t specify anything. You want to "open a link" using a button. This?
– Jéf Bueno
That’s right, buddy, I have a button called new on a page that lists all my records, and when I click on it, I want to call the Create (GET) action, which brings me the sign-up view, you know ?
– Nicola Bogar
Just use CSS to look like an anchor button.
– Jéf Bueno