Get the App
SLTechnology News&Howtos  ›  Development  › 

How to pass parameters and bind data in ASP.NET MVC

Shulou Source: shulou.com Published: 2022-06-03 13:24:37 09月21日 Update

This article will explain in detail how to transmit parameters and bind data in ASP.NET MVC. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

The requirement is like this: in a list page, the user clicks the detailed ammonium button, and the primary key value with the record goes to another page.

In another outer page, get the record data, and then display the record data on the web page.

First use the motion diagram to demonstrate:

The above just passes a value in ng-click, but in ASP.NET MVC, you also need to pass this value to "ASP.NET MVC pass parameter (model)" in another view.

Www.cnblogs.com/insus/p/6148167.html

$scope.Detail = function (code) {var objects = {}; objects.Key = code; objects.Value = ""; objects.Controller = "Code"; objects.Action = "ClauseDetail"; $http ({method: 'POST', url:' / Pass/Redirect', dataType: 'json', headers: {' Content-Type': 'application/json Charset=utf-8'}, data: JSON.stringify (objects),}) .then (function success (response) {if (response.data.Success) {_ window.location.href = response.data.RedirectUrl;} else {alert (response.data.ExceptionMessage) }, function error (error) {alert (response.error.data);};}

The Action of the controller in ASP.NET MVC receives parameters to get the data of the database:

Public ActionResult ClauseDetail () {if (TempData ["Pass"] = = null) return RedirectToAction ("Clause", "Code"); var pass = TempData ["Pass"] as Pass; TempData ["Pass"] = pass; Clause c = new Models.Clause (); c.Code = pass.Key.ToString (); ClauseEntity ce = new ClauseEntity (); var model = ce.ClauseByKey (c). FirstOrDefault (); return View (model) }

After fetching the data from the database, the above gives the view a model. Here is the focus of this article, how to pass the model of ASP.NET MVC to angularjs ng-model:

This is the end of the article on "how to transfer parameters and bind data in ASP.NET MVC". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Data articles parameters databases is in more views good practical content said controllers articles appearance users knowledge web pages key points first use seek truth Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Tech Info Docker Redmi Shulou Technology