1

I am fairly experienced with AngularJS and in the process of coming to terms with ASP.NET MVC while working with an existing application.

I am having trouble finding a satisfactory way to post changes to data in controls that are not in a webform. ASP.NET MVC has a clean and well documented mechanism for posting web form data, but the "right" way to get data from a view into a model with no submit event eludes me.

The code I am working with uses Ajax to achieve this, but I find it jarring to see a view requiring knowledge of communications protocols and addresses. To me this makes the object a hybrid between view and controller.

So where does such a call belong?

  • The View? Is my opinion expressed above wrong?
  • The Model? I don't think so. The model should not be concerned with how it is moved around IMO. It would become a model/controller.
  • The Controller? Seems the right place to me, but we have very strong positions against this expressed, for example, here: ASP.NET MVC: Access controller instance from view

I can't help feeling that there's a mechanism in ASP.NET MVC to POST non-webform values nearly as cleanly as webform values, but in the absence of such a beast I have to choose whether to place HTTP calls in either M, V or C.

I hope this isn't a stupid question.

  • what exactly you want ? – Tejinder Singh Oct 12 '17 at 06:06
  • In other words, must I use AJAX in the view to PUT or POST data to a model? It means tying the view to specific addresses. It seems to me to be forcing a concern on the view that should not be there. The controller seems to me the correct place to be dealing with the methods of moving data. – Murray Lang Oct 12 '17 at 07:14
  • OK, I understand now that the client javascript cannot call the server controller C#, so it seems we're stuck with Ajax in the view, but surely the mechanism for posting form data can be applied somehow to non form data? Maybe I need to wrap a form around every single control on the page and somehow invoke a submit with onchange() or something. To someone used to Angular, ASP.MVC seems to have cavernous holes. – Murray Lang Oct 12 '17 at 09:26

0 Answers0