ASP.NET MVC 2,并列出为隐藏值? [英] ASP.NET MVC 2 and lists as Hidden values?

查看:79
本文介绍了ASP.NET MVC 2,并列出为隐藏值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含列表的视图类,这个列表说明了可用的文件,用户已经上传(呈现一个HTML帮助)。

要保持对提交我已经添加了以下的观点这样的数据:

 <%:Html.HiddenFor(型号=> model.ModelView.Files)%GT;

我希望在mode.ModelView.Files名单将返回到上提交的行动,但它是不是?

这难道不是可能有一个列表,hiddenfield?

更多信息: 用户提交了几个被保存在服务中,当保存的大公被所指向作为GUID和是这个列表被发送回给用户的文件的使保存的图像。该用户在表单中添加一些变化和命中再次提交前往控制操作时,图像列表将是空的,为什么?

BestRegards


解决方案

  

这难道不是可能有一个列表,hiddenfield?


当然,这是不可能。隐藏字段只需要一个字符串值:

 <输入类型=隐藏ID =富NAME =foo的值=富巴/>

所以,如果你需要,你需要多个隐藏字段的列表,列表中的每个项目。如果这些项目都是复杂的对象,你需要一个隐藏字段列表中的每个项目的每个属性。

或者更简单的解决方案是为这个隐藏字段重新present一些独特的标识符:

 <输入类型=隐藏ID =filesIdNAME =filesIdVALUE =123/>

和在你的控制器动作,你会使用这个唯一的标识符,从哪里您最初得到它重新获取您的收藏。

另一种可能的是坚持你的模型到会话(只提我的回答缘故完整性会话,但它不是东西,我真的建议使用)。

Hi,

I have a View class that contains a list, this list explains the available files that the user have uploaded (rendered with an html helper).

To maintain this data on submit I have added the following to the view :

<%: Html.HiddenFor(model => model.ModelView.Files)%>

I was hoping that the mode.ModelView.Files list would be returned to the action on submit but it is not?

Is it not possible to have a list as hiddenfield?

More information : The user submit a couple of files that is saved on the service, when saved thay are refered to as GUID and is this list that is sent back to the user to render the saved images. The user makes some changes in the form and hit submit again the image list will be empty when getting to the control action, why?

BestRegards

解决方案

Is it not possible to have a list as hiddenfield?

Of course that it is not possible. A hidden field takes only a single string value:

<input type="hidden" id="foo" name="foo" value="foo bar" />

So if you need a list you need multiple hidden fields, for each item of the list. And if those items are complex objects you need a hidden field for each property of each item of the list.

Or a much simpler solution is for this hidden field to represent some unique identifier:

<input type="hidden" id="filesId" name="filesId" value="123" />

and in your controller action you would use this unique identifier to refetch your collection from wherever you initially got it.

Yet another possibility is to persist your model into the Session (just mentioning the Session for the completeness of my answer sake, but it's not something that I would actually recommend using).

这篇关于ASP.NET MVC 2,并列出为隐藏值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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