如何处理在ASP.NET MVC中的嵌套形式 [英] How to handle nested forms in ASP.NET MVC

查看:74
本文介绍了如何处理在ASP.NET MVC中的嵌套形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个相当复杂的形式为一对夫妇级联选择 - 即用户在一个组合中选择一个值,另一个组合是根据他们的第一选择填充。

I'm trying to build a fairly complex form which as a couple of cascading selects - i.e. the user selects a value in one combo and the other combo is populated according to their first selection.

我跟着<一个href=\"http://weblogs.asp.net/raduenuca/archive/2011/03/06/asp-net-mvc-cascading-dropdown-lists-tutorial-part-1-defining-the-problem-and-the-context.aspx\"相对=nofollow>如何处理级联教程但我的问题是,我现在已经嵌套表格(在$ C $教程C使用局部视图里面的形式张贴到一个控制器动作加载第二个组合)。我有,我要收集的输入值也是nexted形式的级联选择框我的主要形式。我的问题是,级联选择不发布到正确的控制器动作,而是发布到我的主(外)形式的行动。

I've followed a tutorial on how to handle the cascading but the problem I have is that I now have nested forms (the code in the tutorial uses forms inside partial views to POST to a controller action to load the 2nd combo). I have my main form on which I want to collect the input values but also the nexted forms for the cascading select boxes. The problem I have is that the cascading selection doesn't post to the correct controller action, but instead posts to my main (outer) form's action.

我明白这是一个浏览器正确的行为(如嵌套形式显然不支持),但什么是实现这个正确的方法是什么?

I understand this is the correct behaviour for a browser (as nested forms apparently aren't supported) but what's the correct way to implement this?

推荐答案

使用这个有多个提交一个窗体上的按钮,每个都有不同的控制器操作张贴到:

use this to have multiple submit buttons on one form which each have different controller actions to post to:

http://iwayneo.blogspot.co.uk/2013/10/aspnet-mvc-action-selector-with-list.html

作为级联的东西 - 我将专注于填充这些没有Ajax月1日 - 那么你可以不用担心将这种耀斑 - 如果它不没有工作JS反正你在一个不好的地方。

as for cascading stuff - i would focus on populating these without Ajax 1st - then you can worry about adding this sort of flare - if it doesn't work without JS anyway you're in a bad place.

我会填充时首先加载的形式,有一个下一步按钮来填充级联下一个下拉列表中第一个下拉列表。这个提交可以用上述方法发布到一个动作,然后根据一号下拉菜单中选择填充第二个数据集。

I would have the 1st dropdown populated when you initially load the form and have a "next" button to populate the next dropdown in the cascade. this submit can use the method above to post to an action which then populates the second data set based on the selection of the 1st dropdown.

有意义吗?

那么,你怎么认为阿贾克斯后点是由你,但你有一个非常坚实的基础,建立这样的东西,你就会有它在最小的技术方案的工作。

Then how you ajax that after the point is up to you but you'll have a very solid foundation to build up stuff like that as you will have it working in the minimal tech scenario.

W://

这篇关于如何处理在ASP.NET MVC中的嵌套形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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