2 回答

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超6個(gè)贊
親愛的有兩種方式
如果您必須使用 Razor,則應(yīng)在 mvc 控制器中使用 API,從 api 獲取數(shù)據(jù)并將其在模型中返回到 Razor 視圖,然后您將有強(qiáng)類型模型在 Razor 視圖中使用
如果你沒有被束縛,那么它非常簡單,如果你在javascript代碼中獲取數(shù)據(jù)。只需使用它來使用JavaScript代碼填充您的視圖即可。
如果您使用的是 angular 1.x,那么下面是一個(gè) angularjs 1.x 表單示例
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="formCtrl">
<form novalidate>
First Name:<br>
<input type="text" ng-model="user.firstName"><br>
Last Name:<br>
<input type="text" ng-model="user.lastName">
<br><br>
<button ng-click="reset()">RESET</button>
</form>
<p>form = {{user}}</p>
<p>master = {{master}}</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('formCtrl', function($scope) {
$scope.master = {firstName:"John", lastName:"Doe"};
$scope.reset = function() {
$scope.user = angular.copy($scope.master);
};
$scope.reset();
});
</script>
</body>
</html>

TA貢獻(xiàn)1900條經(jīng)驗(yàn) 獲得超5個(gè)贊
開發(fā)人員按照您在評論中告訴,要通過html綁定數(shù)據(jù),您可以嘗試使用此解決方案。
首先在 .cshtml 的標(biāo)頭部分中初始化 .cshtml 中的模型,然后使用 @model 并通過添加 來提供其字段名稱。(點(diǎn))對數(shù)據(jù)進(jìn)行簽名并將其綁定到 html 控件
- 2 回答
- 0 關(guān)注
- 144 瀏覽
添加回答
舉報(bào)