-2

I would like to save (and eventually view data) from a view in asp.net mvc application using entity framework. The model is as follows:

public class Class
    {
        public Class()
        {
            this.params1= new HashSet<Param1>();
            this.params2= new HashSet<Param2>();
        }

        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public long Id { get; set; }               

        public long param3{ get; set; }

        public long param4{ get; set; }

        public virtual ICollection<Param1> params1 { get; set; }

        public virtual ICollection<Param2> params2{ get; set; }
    }

The display of data in the view is made in a way that it is included in different sections ( params1 are displayed in a grid while params2 are displayed in forms). I'm not quite sure whether I should pick the data with javascript code and then send it to the controller to save data or if I can achieve this with html helpers to directly go from the cshtml file to the controller file.

Claritta
  • 189
  • 1
  • 4
  • 17
  • 1
    Either way is doable, it is very hard to give a more concrete advice with such a vague problem description. Do you have any specific question? – Andrei Feb 21 '17 at 12:09

1 Answers1

0

If you wish to put everything in multiple forms, there's another StackOverflow answer which demonstrates this really concisely.

https://stackoverflow.com/a/7843397/4636912 You could also submit these using Jquery:

    function submitData() {
        var id = $('#id').val();
        var param1 = $('#param1').val();
        var param2 = $('#param2').val();
        var param3 = $('#param3').val();
        var param4 = $('#param4').val();

        $.ajax({
            url: "YourControllerAction",
            type: "POST", //Or "GET" depending on your action
            data: { id: id, param1: param1, param2: param2, param3: param3, param4: param4 },
        }).done(function (response) {
            $("#itemList").html(response); //if you wish to populate your current view with a partial view or data.
        });
    };
Community
  • 1
  • 1