MVC3输入提交 [英] MVC3 input submit

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

问题描述

我有在MVC3 C#.NET Web应用程序的索引页。我的建议模型的索引视图包含输入提交按钮:

I have an Index page in an MVC3 C#.Net web app. The Index View of my Proposal Model contains an input submit button:

 <input  type="submit" name="Create" id="Create" value="Create New Proposal" style="width: 200px" />

在单击该按钮,我想调用的议案模型创建视图。不过,我不能在控制器的建议得到任何方式的新建按钮,输入时点击开火。我可以叫索引Post方法?该建议创建get方法?任何想法?

When the button is clicked, I want to invoke the Create View on the Proposal Model. However, I can't get any method in the Proposal Controller to fire when clicking on the "create New" input button. Can I call the Index Post method? The Proposal Create get method? Any ideas?

推荐答案

您需要一个表单中的提交按钮和重载的ActionResult 在你的控制器,它使用 HttpPost 属性。

You need your submit button inside a form and an overloaded ActionResult in your controller which uses the HttpPost attribute.

喜欢的东西...

控制器

public ActionResult Index()
{
   return View(new MyViewModel());
}

[HttpPost]
public ActionResult Index(MyViewModel model)
{
   // do stuff with model
}

查看

@using(Html.BeginForm())
{
   <input type="submit" value="Go" />
}

这会使一个表格,并上传到你的控制器Index操作的结果。

That would render a form and post it to the Index action result in your controller.

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

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