mvc4中的会话存储 [英] Session storage in mvc4

查看:56
本文介绍了mvc4中的会话存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主视图页面中创建了一个文本框和一个按钮。我创建了一个名为_PartialView的部分视图页面。我的要求是当用户在文本框中放置内容并单击按钮时,部分页面将显示用户在文本框中输入的值。如何使用会话存储实现它?

解决方案

为什么需要会话存储以及任何服务器端操作?这是在不需要回发的同一页面上发生的操作。会话数据中没有任何内容存储。您可以使用JavaScript来读取控件并将此值写入其他位置,例如:

 < span class =code-keyword> var  myTextBox =  document  .getElementById( < span class =code-string> textBox); 
var someParagraph = document .getElementById( someParagraph);

// ...

someParagraph .innerHTML = myTextBox.value;
// 仅为什么? : - )



类似的东西...



-SA

I have created a text box and a button in my main view page. I have created a partial view page also named "_PartialView". My requirement is when a user put something in the text box and click on the button, the partial page will display with the value which the user has entered in the text box. How to implement that with Session Storage?

解决方案

Why would you need session storage for this, and any server-side operation at all? This is the action which happens on the same page which does not need a postback. There is nothing to store in session data. You can just use JavaScript to read the control value and write this value elsewhere, such as in:

var myTextBox = document.getElementById("textBox");
var someParagraph = document.getElementById("someParagraph");

//...

someParagraph.innerHTML = myTextBox.value;
// only why? :-)


Something like that…

—SA


这篇关于mvc4中的会话存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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