Pass parameters via jquery to my model

-1

I 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 do not know how to do it. I have this model: MontaArvoreAcao.cs. This does not work, it gives error.

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

How do I do it then?

    
asked by anonymous 29.09.2014 / 21:32

2 answers

1

As I understand it, you want to populate a property in your model through Jquery.

If this is really the case, you can put a Hidden input in the view representing your model, and change the value of it through JQuery. If the element already exists (not being a hidden one), just grab the HTML element and change its value. MVC performs model binding to send the model to its controller via 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 should change the Attribute property of the FooModel model to the value "NewMySourceType" as per JQuery script.

    
30.09.2014 / 19:51
-2

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

    
29.09.2014 / 22:56