I create a ViewModel:
我创建了一个视图模型:
public class TestViewModel
{
public int RegionId { get; set; }
public int WeekId { get; set; }
public int SubregionId { get; set; }
public int YearId { get; set; }
}
I create a Testcontroller which have two actions Index and Transfer. In the Index Action i initialize the viewModel and pass the model to index View. In the Index View I use @Url.Action("Tranfer",Model) to pass model back to Transfer action.but in the Transfer action. i can't get the correct model.Can any body tell me the solution?
我创建了一个Testcontroller,它有两个动作索引和传输。在索引操作中,我初始化viewModel并将模型传递给Index视图。在索引视图中,我使用@Url.Action(“Tranfer”,Model)将模型返回到传输操作。但在转移行动中。我找不到正确的模型。谁能告诉我解决办法吗?
Thanks!!!
谢谢! ! !
1 个解决方案
#1
1
Url.Action
works as a Url with Query String
Url。操作作为带有查询字符串的Url工作
Query strings
are like dictionary : {key, value} pairs. Therefore you cannot pass your class objects in query strings.
查询字符串类似于dictionary: {key, value}对。因此,不能在查询字符串中传递类对象。
But, what you can do, is to pass this the id for your model object and then use that id to load your object on server.
但是,您可以做的是,将这个id传递给模型对象,然后使用该id在服务器上加载您的对象。
#1
1
Url.Action
works as a Url with Query String
Url。操作作为带有查询字符串的Url工作
Query strings
are like dictionary : {key, value} pairs. Therefore you cannot pass your class objects in query strings.
查询字符串类似于dictionary: {key, value}对。因此,不能在查询字符串中传递类对象。
But, what you can do, is to pass this the id for your model object and then use that id to load your object on server.
但是,您可以做的是,将这个id传递给模型对象,然后使用该id在服务器上加载您的对象。