MVC 4表单行动问题 [英] MVC 4 Form Action Problem

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

问题描述

我正在开发一个Mvc 4中的网络项目。我有一个问题让我疯狂。



我生成了自动Ef控制器以便查看视图。问题是我需要在details.aspx中输入一个自动生成的表单。在这个自动生成的视图页面中,当我插入一个简单的Html表单时,例如:



 <  表格    action   =  / mydata / createx   方法  = 发布 >  


< fieldset >
& 图例 > yorum < / legend >


输入您的注释< br / >


< ; textarea id < span class =code-keyword> = TextArea1 cols = 20 = 2 name = yorumicerik > < / textarea > < br / >


< 输入 type = 提交 name = 发布 / >

< / fieldset >
< / form >





它不做任何动作并回贴到页面本身。



当我查看这个detail.aspx的源代码时,我遇到了这样一个废话:



 <  表格   方法  = 发布   操作  =  7    id   =  form1 >  
< div class = aspNetHidden >
< 输入 type = hidden name = __ VIEWSTATE id = _ _VIEWSTATE value = / wEPDwULLTE5ODYxNTE1MjIPZBYCZg9kFggiw9kFgJmDw8WAh4LXyFEYXRhQm91bmRnZGRkb8RYMOq7pqebRBzpJ7VukpsweU4PIj77dptlTxSVaSY = / >
< / div >







此处页面发布到相关模型的id参数。如何更改动作网址?我的意思是我想在这里插入yorum / createx而不是7。



回复的Thx。



有趣的是,表单适用于其他视图,例如创建,删除,编辑,但仅在详细信息视图中它不起作用:D

解决方案

我解决的任何问题通过定义一个名为Details的方法并在方法之前放置[HttpPost,ActionName(Details)]来解决问题。 :)

hi,I'm developing a web project in Mvc 4.I have a problem which drivez me crazy .

I generated automated Ef Controllers so the views.The Problem is I need to input a form in details.aspx which was generated automatically .In this automatically generated view page when I insert a simple Html Form such as:

<form action="/mydata/createx" method="post">


    <fieldset>
        <legend>yorum</legend>


        Enter Your Comment<br />


        <textarea id="TextArea1" cols="20" rows="2" name="yorumicerik" ></textarea><br />


            <input type="submit" name="Post" />

    </fieldset>
    </form>



It does no action and posting back to page itself.

when I looked at the source code of this detail.aspx I come across such a crap:

<form method="post" action="7" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE5ODYxNTE1MjIPZBYCZg9kFgICAw9kFgJmDw8WAh4LXyFEYXRhQm91bmRnZGRkb8RYMOq7pqebRBzpJ7VukpsweU4PIj77dptlTxSVaSY=" />
</div>




here the page posts to id parameter of the related model.How can I change the action url in here ? I mean I wanna insert "yorum/createx" instead of 7 here.

Thx for the replies.

The interesting point is, the form works in other views such as create,delete,edit but only in details view it doesnt work :D

解决方案

Any I Solved the problem by defining a method named same as Details and putting [HttpPost,ActionName("Details")] before the method. :)


这篇关于MVC 4表单行动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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