MVC2:我怎么可以读取控制值一个动作链接? [英] MVC2: How can I read control values for an action link?

查看:334
本文介绍了MVC2:我怎么可以读取控制值一个动作链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我传递一些模型信息到ActionLink的,但我也想向用户提供的页面上的某些输入值的操作。举例来说,如果我有这样的事情:

I'm passing in some model information to an ActionLink, but I'd also like to provide the action with the values of some inputs on the page. For example, if I had something like this:

<input Name="MyInput" />

<%: Html.ActionLink("MyAction", "MyController", Model.Value);

我想动作要知道这两个Model.Value(这是通过参数传递),而MyInput的价值。通常我会用的FormCollection,但我不能在这种情况下,因为我不会做一个提交。

I'd like the action to be aware of both Model.Value (which is passed in via parameter), and the value of MyInput. Normally I would use a FormCollection, but I can't in this instance since I'm not doing a submit.

因此​​,如何能我通过My​​Input的价值MyAction?我会到一个名为MyInput属性添加到我的模型?假设将工作,是否有更简单的方法,或至少一种不涉及修改模型?

So how can I pass the value of MyInput to MyAction? Would I have to add a property named MyInput to my model? Assuming that would work, is there an easier way, or at least one that doesn't involve modifying the model?

推荐答案

有没有办法在HTML做到这一点,所以没有办法在ASP.NET MVC做到这一点。

There is no way to do this in HTML, thus there isn't a way to do this in ASP.NET MVC.

有这两个可能的解决方案,你可以选择:

There are two possible solutions to this that you can choose from:


  1. 使用JavaScript这样,当用户编辑文本框,你动态地改变锚标记的价值,包括他们在类型的。因为在服务器上运行,不能使用ASP.NET路由,这和你需要客户端code。

  1. Use JavaScript such that when the user edits the textbox you dynamically change the value of the anchor tag to include what they typed in. You can't use ASP.NET routing for this because that runs on the server and you need client side code.

做一个表单提交,而不是链接。这是HTML的推荐方式。当用户提交数据,它应该是在一个形式。在表单标签包装的一切,然后将文本框和一个按钮在那里。设置窗体的行动是你希望它张贴到的URL。

Do a form submit instead of a link. This is the recommended way in HTML. When the user is submitting data, it should be in a form. Wrap everything in a form tag and place the textbox and a button in there. Set the form's action to be the URL that you want it to post to.

这是因为我把这个问题相同的反应,但其他问题的提问者可能有一个稍微不同的想法。

This is the same response as I put in this question, though the asker of the other question might have had a slightly different idea.

这篇关于MVC2:我怎么可以读取控制值一个动作链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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