Call Get action that returns a view by jquery ASP.NET MVC

Asked

Viewed 323 times

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?

  • What would that form look like @LINQ?

  • Put a href on Button ?

  • Create a link and call the URL that will trigger the action and return to view.

  • Button may not have href, but that’s the way. Use a tag a and put the href

  • Is that correct? Because the visual studio gives a warning that you can’t have a button inside the tah <a>

  • <a href="@Url.Action("Create","Parents")"> <button id="btnNovo" type="button" class="btn btn-info"> New </button> </a>

  • Can’t have a button (<button>) inside an anchor (<a>).

  • @LINQ, could you tell me the best way, if you could set an example I would be very grateful.

  • 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?

  • 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 ?

  • Just use CSS to look like an anchor button.

Show 7 more comments

1 answer

3


Based on the comments, what you want is to use CSS for anchor (<a>) look like a button (<button>).

.btn {
  appearance: button; /* CSS3 */    
  -webkit-appearance: button; /* Safari and Chrome */
  -moz-appearance: button; /* Firefox */
  -ms-appearance: button; /* Internet Explorer */
  -o-appearance: button; /* Opera */
  cursor: default;
  padding: 5px 15px; 
  color: #000;
  text-decoration: none;
}
<a class="btn" href="http://www.google.com">Sou um botão</a>

  • That’s right, for me I needed to use the <button> tag, and not directly use the <a tag>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.