Pass parameters via jquery to my model

Asked

Viewed 809 times

-1

I’ve always passed paramatros to my controller like this:

url: '/Minha_Controller/Minha_Função',
....

Now I need to pass parameters directly to My Model and I don’t know how to do it. I have this model: Montaarvoreacao.cs. So it doesn’t work, it’s wrong.

url: '/Minha_Model/Minha_Função',
.....

As I do then?

  • 1

    Pass parameters directly to model? This is wrong.

  • Okay, I accept guidance.

  • Do you want to put information into your model through Jquery to get it to the filled controller? That’s it?

2 answers

1

From what I understand, you want to fill a property in your model through Jquery.

If this is the case, you can place a hidden input in the view representing your model, and change the value of the model through Jquery. If the element already exists (not an Hidden), just take the HTML element and change its value. MVC performs the Binding model to send the model to its controller through the elements name.

For example:

@model Meu.Model.FooModel

@using (Html.BeginForm())
{
       @Html.HiddenFor(e => e.Atributo, new { id = "AtributoDoModel" })
       <input type="submit" val="Enviar" />
}

<script>
        $(document).ready(function(){
                $("#AtributoDoModel").val("NovoValorDoMeuAtributo");
        });
</script>

The above code must change the Foomodel Attribute property to the "Novovalordomeuattribute" value, as scripted in Jquery.

-2

In your controller method you will receive your model. In order for the values of your model to be correctly populated in the controller it will be necessary that in the View you use the fields with the same model name. Ex.: Name field in model In view use:

Browser other questions tagged

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