0

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

      //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
    }
4

1 回答 1

1

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

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

这将在请求正文中以 Form Encoded 的形式传输数据,并将数据保留在查询字符串之外。

于 2012-10-15T23:29:56.547 回答