是否可以在mvc 3中将对象作为路由值传递? [英] Is it possible to pass object as route value in mvc 3?

查看:67
本文介绍了是否可以在mvc 3中将对象作为路由值传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重构我的一些代码,我想知道是否可能是这样的:

I'm trying to refactor some of my code and i'm wondering if it is possible something like this:

这是我的cshtml的一部分:

This is part of my cshtml:

 <a href="@Url.Action("Vote", "Ideas", new { id = item.Idea.Id, pageMetadata = Model.PageMetadata, numberOfVotes = 2 })">

这是调用操作:

public ActionResult Vote(string id,PageMetadata pageMetadata, int numberOfVotes = 1)

PageMetadata 是我的课程。

当我在cshtml网站中进行调试时, pageMetadata 是正确的,但是当操作调用 pageMetadata 时,它会变为 null 。我是一些愚蠢的错误还是所有想法都错了?
感谢您的帮助。

When im debbuging in cshtml site pageMetadata is correct,but when action is invoking pageMetadata it's becoming to null. Do I some stupid mistake or all idea is wrong? Thanks for any help.

推荐答案

查询字符串就像字典:{key,value}对。因此,您不能在查询字符串中传递类对象。

Query strings are like dictionary : {key, value} pairs. Therefore you cannot pass your class objects in query strings.

但是,您可以做的是将其传递给模型对象的ID,然后使用该ID将对象加载到服务器上。

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.

现在,您正在处理错误的概念! :-)

Right now, you are working on a wrong notion ! :-)

这篇关于是否可以在mvc 3中将对象作为路由值传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆