MVC2.0表单提交 [英] MVC2.0 form Submit

查看:56
本文介绍了MVC2.0表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
首先我使用mvc2.0
我不想使用

hi
first I''m using mvc2.0
i don''t want to use

<br />
<![CDATA[<% using (Html.BeginForm()) { %>]]><br />


而是我想使用<form>标签
并将其操作设置为/Details/Delete/id

id将是其删除按钮被单击的记录的ID.


如何控制此行为


rather I want to use <form> tag
and want to set its action as /Details/Delete/id

id will be the id of that record whose Delete Button is clicked


how can I control this behaviour

推荐答案



MVC旨在在回发时将页面模型回发到服务器端.这意味着表单的动作需要由框架控制.

您可以在其他页面上创建视图以处理删除,并使用ajax调用该页面.

以下是一个简单介绍ajax的URL.

http://devzone.skillfusion.com/ajaxArticle4.php
Hi,

MVC is designed to post the model for the page back to server side on postback. This means that the action of the form needs to be controlled by the framework.

You can create a view on a different page to handle the delete and call the page using ajax.

There following is a url with a simple introduction to ajax.

http://devzone.skillfusion.com/ajaxArticle4.php


The "HTML." methods in MVC are convienience methods that generate HTML code so you can always override them with your own HTML.



数量有限的细节使我很难理解为什么您需要覆盖表单发布操作.

根据您的问题,看起来您可能有一个带有多个删除按钮的网格.您可以将onclick事件添加到删除按钮中,该事件看起来像这样:

onclick =''window.location ="/Details/Delete/<%= item.id%>;返回false;''

"item.id"将是网格线上显示的项目的ID或您要传递回的任何ID.

如果您确实要更改操作并发布表格,则可以使用以下内容:

onclick =''document.forms [0] .action ="/Details/Delete/<%= item.id%>";; document.forms [0] .submit(); return false;''



The limited amount of details make it difficult for me to understand why you would need to override the form post action.

Based on your question it looks like you may have a grid with multiple delete buttons. You can add an onclick event to your delete button that would look something like this:

onclick=''window.location="/Details/Delete/<%= item.id %>"; return false;''

"item.id" would be the ID of the item being displayed on the grid line or any ID you want to pass back.

If you really want to alter the action and post the form you can use the following:

onclick=''document.forms[0].action="/Details/Delete/<%= item.id %>"; document.forms[0].submit(); return false;''




<% using (Html.BeginForm()) { %> 具有重载方法 Html.BeginForm(string actionname, string controllerName, RouteValueDictionary routeValues).

所以这段代码...
Hi

the <% using (Html.BeginForm()) { %> has an overload method Html.BeginForm(string actionname, string controllerName, RouteValueDictionary routeValues).

So this code...
<br />
<% using (Html.BeginForm("myTestmethod", "myTestController", new { id = "123" }))<br />
       { %><br />


将生成此html标记....


will generate this html markup....

<br />
<br />
<form action="/myTestController/myTestmethod/123" method="post"><br />
<br />



如您要求传递ID.但是,您需要为此设置一条匹配的路线..

所以在您的路线中..还要定义任何特定路线...




as you have asked passing the id. However you need to have a matching route for this..

so in your routes ..define any specific routes as well...


routes.MapRoute(
               "Default", // Route name
               "{controller}/{action}/{id}", // URL with parameters
               new { controller = "myTestController", action = "myTestmethod",  id = UrlParameter.Optional } // Parameter defaults
           );



希望对您有帮助



I hope this helps you


这篇关于MVC2.0表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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