如何在mvc4中使用html.beginForm返回Model [英] how return Model with html.beginForm in mvc4

查看:192
本文介绍了如何在mvc4中使用html.beginForm返回Model的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi

i在HttpGet索引控件中编写此代码:

hi
i write this code in HttpGet Index Control :

[HttpGet]
        public ActionResult Index(int id)
        {
		var model=_db.nezam.tolist();
		return view(model);
		}





并且在视图中我有一个表格:



and in view i have a form :

@using(Html.BeginForm()){
<input type="text" name="cap" />
<input type="submit"  value="OK" />
}





in httpost我写道:



in httpost i write :

[HttpPost]
    public ActionResult Index(string cap)
      {
          string st=HttpContext.Session["captcha"].ToString();
          if (cap == st)
          {
              return Content("true");
          }
          return View(?);
      }





当我运行我的项目并点击确定按钮时给我这个错误:



when i run my project and click on ok button give me this error :

System.NullReferenceException: Object reference not set to an instance of an object.





这是真的,因为我没有发送任何模型来查看,但我不知道如何从html.beginform获取模型,然后再将其发送到另一个视图,===返回查看(?)?????



it is true because i dont sent any model to view , but i dont know how get model from html.beginform and next send it to view again ,=== return View(?)?????

推荐答案

你真的需要拿起关于MAC的书。除了要发布表单之外,还有很多其他概念缺失。
You REALLY need to pick up book on MAC. There's plenty more concepts you're missing on top of just getting a form to post.


这篇关于如何在mvc4中使用html.beginForm返回Model的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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