将对象传递给mvc中的action方法将属性放在querystring中

时间:2012-10-15 23:03:30

标签: asp.net asp.net-mvc

我正在将一个对象传递给一个action方法,并且该action方法显示了视图,但它具有查询字符串中的所有属性,我不希望这样(我有一个不能传入url的长json字符串)。如何传入模型对象而不是在查询字符串中?此外,当您具有强类型视图时,Model存储的对象值在哪里?谢谢你的帮助。

      //This works fine when I am calling /controller/uploader
        public ActionResult Uploader(Model model)
        {
        //logic
        return View(model);
        }

        //But when I am on another method and want to call uploader it does pass the object but puts //all the data in a querystring
        public void DoSomething(string val, string anotherval){
        Model model = new Model();
        Uploader(model);//This passes the object but when uploader page shows it has all the    //model object properties in querystring and I do not want that.

 return RedirectToAction("Uploader",model);//or this does the same thing
    }

1 个答案:

答案 0 :(得分:1)

尝试在html表单上使用POST方法:

<form action="/uploader" method="POST">
    <!-- maybe some input elements? -->
    <input type="submit" />
</form>

这会将数据传输为请求正文中的表单编码,并将数据保留在查询字符串之外。