Events in ASP.NET MVC?

Events in ASP.NET MVC?

kstankiewiczkstankiewicz Posts: 8Questions: 3Answers: 1

Does handling Events work differently in ASP.NET MVC than it does in regular ASP.NET? In all the Editor examples about Events they use System.Web.Http instead of System.Web.MVC, and they use:

var request = HttpContext.Current.Request;

instead of:

var formData = HttpContext.Request.Form;

As it is in the MVC examples. Does this affect the way Events work? I'm trying to set up an event that updates a field when another field is edited, but I can't get any events working in my MVC project.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,635Questions: 1Answers: 10,092 Site admin
    Answer ✓

    The Editor examples use MVC.NET Web API as that fits in really nicely with how Editor makes async requests to get JSON data. The use of HttpsContext.Current.Request is correct in that framework.

    However, it is perfectly possible to use a more traditional ASP.NET MVC pattern as described in this manual page.

    Allan

  • kstankiewiczkstankiewicz Posts: 8Questions: 3Answers: 1

    Thank you Allen, good to know that it is supported. Now I'm wondering what I'm doing wrong as I am unable to trigger Events in my project. This manual page goes over usage of Events in .NET:

    https://editor.datatables.net/manual/net/events

    I followed the first example where editing a field causes another field to be changed, in the Controller I set the Field type to 'Edit' and set up the PostEdit event the same as in the example.

    That page does not mention adding anything to the view to trigger this, would that be required? I see on the Events page in the manual they are doing things with JS in the view:

    https://editor.datatables.net/manual/events

  • kstankiewiczkstankiewicz Posts: 8Questions: 3Answers: 1
    Answer ✓

    An update- I was trying to use PostEdit to edit a field when another field is changed (in the same row), it wasn't working but it does when I use PreEdit, I may have misunderstood how this works, seems like I'm good to go now. Thanks again Allan

  • allanallan Posts: 61,635Questions: 1Answers: 10,092 Site admin

    Good to hear :).

    PostEdit happens after the row information has been written to the database (for all edited fields). PreEdit happens before writing to the db. There aren't individual field level events triggered - just row level.

    Allan

This discussion has been closed.