我正在使用knockoutjs来绑定选择列表.这是一个示例 ,我想获取选定的选项文本而不是选定的值.
如何使用knockoutjs获取它?
<select id="projectMenu" name="projectMenu" data-bind="
value: selectedProject,
options: projectFilters,
optionsText: 'a',
optionsValue: 'b',
optionsCaption: '-- Select Project --'
">
</select>
<b>Selected Project:</b> <span data-bind="text: selectedProject"></span>
Run Code Online (Sandbox Code Playgroud) 在我的一个 Web 应用程序中,我需要在 5 分钟内会话超时时弹出警报。用户可以选择继续延长会话或立即注销。
在 Web.config 中将会话超时设置为 30 分钟:
<sessionState mode="InProc" timeout="30">
Run Code Online (Sandbox Code Playgroud)
由于 ASP.NET MVC 没有提供检查剩余会话超时的方法,我提出了如下解决方案:
在 Global.asax 中,它将当前会话的上次访问时间作为会话变量进行跟踪。如果传入请求不是只读会话状态(见下文),则上次访问时间会话变量将更新为当前时间。否则,会话变量的值将设置为当前时间。
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
var context = HttpContext.Current;
if (context != null && context.Session != null && !context.Session.IsReadOnly)
{
context.Session["_LastAccessTime"] = DateTime.Now;
}
}
Run Code Online (Sandbox Code Playgroud)
在我的会话控制器中,我将会话状态行为设置为只读。对此控制器的请求既不会重置会话,也不会刷新我的上次访问时间会话变量。
[SessionState(SessionStateBehavior.ReadOnly)]
public class SessionController : BaseController
{
[AjaxOnly]
public ActionResult GetRemainingSessionTimeout()
{
if (!Request.IsAjaxRequest())
{
return Content("Not an Ajax call.");
}
var remainingSessionTimeout = 0;
if (Session["_LastAccessTime"] != null)
{ …Run Code Online (Sandbox Code Playgroud) 我正在使用MVC4并尝试使用knockoutjs库.如果我使用传统的提交点击而不使用Knockoutjs库,表单会将数据提交给控制器.我正在使用knockoutjs映射插件从服务器转换viewmodel以创建客户端viewmodel,然后尝试将其扩展到客户端.
ko.mapping.fromJS(model);ko.toJSON(model)使用jQuery通过ajax发送时将其转换回来.我在服务器上收到的数据为空.此外,当我登录ko.toJSON(model)控制台时,我得到以下内容:
{
"FirstName": "foo",
"LastName": "foo1",
"Address": "United Kingdom",
"Age": 22,
"__ko_mapping__": {
"ignore": [],
"include": ["_destroy"],
"copy": [],
"observe": [],
"mappedProperties": {
"FirstName": true,
"LastName": true,
"Address": true,
"Age": true
},
"copiedProperties": {}
}
}
Run Code Online (Sandbox Code Playgroud)
在将js对象转换回json格式以将数据发送到服务器时,我似乎做得不对.以下是我的所有代码:
控制器代码:
public class PersonController : Controller
{
PersonViewModel viewModel = new PersonViewModel();
//
// GET: /Person/
[HttpGet]
public ActionResult Index()
{
return View(viewModel);
}
[HttpPost]
public ActionResult Index(PersonViewModel viewModel)
{
if (ModelState.IsValid)
{
}
return …Run Code Online (Sandbox Code Playgroud) 我有这个代码
class parent
{
public void sleep()
{
// Some Logic
}
}
class Child : Parent
{
public void sleep()
{
// some logic
}
}
class Implement
{
Child ch = new Child();
ch.sleep();
}
Run Code Online (Sandbox Code Playgroud)
但是现在我想通过使用已经创建的子类的实例来访问父类的sleep()方法.