如何在不使用隐藏字段的情况下将数据从视图传递到mvc3 razor中的控制器 [英] how to pass the dat from view to controller in mvc3 razor without using Hidden field

查看:89
本文介绍了如何在不使用隐藏字段的情况下将数据从视图传递到mvc3 razor中的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mvc razor中隐藏字段的替代

在我的项目中..



1.我创建了一个包含10个属性的模型/>
2.我在get动作中使用该模型,并为这10个属性分配数据库值。

3.并传递这些值以通过模型查看..

4.在视图中我只显示了2个可编辑的字段,剩下8个字段未在视图中使用。

5.但是当我按下提交按钮时我想要传递2并保持8字段..

6.实际上我正在尝试这个但是在post方法中我得到null到剩下的8个字段..

7.我们可以维护8个字段使用@html.HiddenFor()..

8.但我的要求是不使用隐藏字段,会话和缓存..来维护数据来自get方法查看和查看发布在mvc3 Razor



提前致谢

Rangababu

Alternative for Hidden fields in mvc razor
In MY project ..

1. I created a model with 10 properties
2.i am using that model in get action and assign those 10 properties with database values.
3.And pass those values to view through the model..
4.And in view i displayed only 2 fields with editable and remain 8 fields are not used in view.
5.but when i was press submit button i want pass 2 and remain 8 fields ..
6.actually i am trying for this but in post method i get null to the remain 8 fields ..
7.We can maintain 8 fields in view using @html.HiddenFor()..
8.but my requirement is without using hidden fields,session and cache ..to maintain data from get method to view and view to post in mvc3 Razor

Thanks in advance
Rangababu

推荐答案

您应该设置值数据库到任何输入con trols。如果你不想设置隐藏字段使用,如下所示。



创建一个div并在div中添加样式display:none并放置其余部分div中的字段并设置textBoxes中的所有值。

You should set the values from the database to any of the input controls.If you don't want to set in hidden field use like below.

Create a div and add a style display:none to the div and place the remaining fields inside the div and set all the values in textBoxes.
<div style="display:none">
//Set your remaining input field here
</div>





我认为使用hiddenfield没有问题,因为你正在使用post方法。它是一种安全的方法。



希望这有帮助



I think there is no problem of using hiddenfield because your are using post method.It is a secured method.

Hope this helps


我想到的最好方法是使用JQuery ajax调用来发送参数来控制ler。

这种方式你需要绑定你的控件和一些额外的属性,这些属性是你在Controller上发布的属性。



首先在您的视图而不是隐藏字段中,您可以向现有控制器添加属性,例如:









现在在JavaScript部分放置文档就绪部分,如:


The best way to my mind is to use JQuery ajax call to send parameters to controller.
This way you need to bind your control with some extra attributes which are your properties to post on Controller.

First of all in your view instead of hidden field you can add attribute to existing controller like:




Now in JavaScript section put on Document ready portion like:


(document).ready(function(){

//编写处理程序以绑定函数以提交按钮单击查看


(document).ready(function(){
// Write handler to bind function to submit button Click in View


这篇关于如何在不使用隐藏字段的情况下将数据从视图传递到mvc3 razor中的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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