2016-05-18 86 views
0

我在asp.net创建MVC以下数据模型变量查看访问:ASP.NET控制器返回

public class DetailModel 
{ 
public string name { get; set; } 
public string value { get; set; } 
public Highcharts chart { get; set; } 
} 

在控制器I累积数据:

public ActionResult detail() 
{ 
var viewModel = new DetailModel(); 

Highcharts chart = new Highcharts("chart") .... 

viewModel.chart = chart; 
viewModel.name = "test string"; 
viewModel.value = "1a" 

return View(viewModel); 
} 

在视图模型我想要访问vieModel数据但它不起作用。

我已经用下面的代码试了一下:

<%: viewModel.value %> 

<%: viewModel %> 

@(Model) 

或者是这种错误的方式将多个值交给视图?

回答

0

你需要告诉搜索什么样的模式,它应该通过在期待访问模特属性@model陈述在您的视图顶部:

<!-- The fully qualified name may vary --> 
@model YourProject.Models.DetailModel 

一旦y您可以使用Model参考此模型中的任何属性,如下例所示:

<!-- Referencing the name property --> 
Name: @Model.name 
<!-- Referencing the name property --> 
Value: @Model.value 
<!-- You can access the properties of your chart as well --> 
@Model.chart.YourPropertyHere 
0

你应该确定你的模型像这样

@model DetailModel 

,你可以这样

@Model.name 

@Model.value 
相关问题