- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试让它正常工作(现在已经 2 天了)。我正在处理一个日志,我从 jQuery 调用 Controller 操作,向其传递一个 JSON 对象(利用 json2.js)并从 Controller 返回一个 Json 对象。我可以很好地调用该操作,但不能将响应放在我想要的位置,它只是打开一个新窗口,并将其打印在屏幕上:
{"Message":"Invalid username/password combination"}
URL 看起来像 http://localhost:13719/Account/LogOn,因此不是调用操作也不重新加载页面,而是将用户带到 Controller ,这不好.
现在对于一些代码,首先是 Controller 代码
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl = "")
{
if (ModelState.IsValid)
{
var login = ObjectFactory.GetInstance<IRepository<PhotographerLogin>>();
var user = login.FindOne(x => x.Login == model.Username && x.Pwd == model.Password);
if (user == null)
return Json(new FailedLoginViewModel { Message = "Invalid username/password combination" });
else
{
if (!string.IsNullOrEmpty(returnUrl))
return Redirect(returnUrl);
else
return RedirectToAction("Index", "Home");
}
}
return RedirectToAction("Index", "Home");
}
以及 jQuery 代码
$("#signin_submit").click(function () {
var login = getLogin();
$.ajax({
type: "POST",
url: "../Account/LogOn",
data: JSON.stringify(login),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
error: function (xhr) {
$("#message").text(xhr.statusText);
},
success: function (result) {
}
});
});
function getLogin() {
var un = $("#username").val();
var pwd = $("#password").val();
var rememberMe = $("#rememberme").val();
return (un == "") ? null : { Username: un, Password: pwd, RememberMe: rememberMe };
}
如果您还需要在此处查看实际的登录表单
<fieldset id="signin_menu">
<div>
<span id="message"></span>
</div>
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("LogOn", "Account", FormMethod.Post, new { @id = "signin" }))
{%>
<% ViewContext.FormContext.ValidationSummaryId = "valLogOnContainer"; %>
<%= Html.LabelFor(m => m.Username) %>
<%= Html.TextBoxFor(m => m.Username, new { @class = "inputbox", @tabindex = "4", @id = "username" })%><%= Html.ValidationMessageFor(m => m.Username, "*")%>
<p>
<%= Html.LabelFor(m=>m.Password) %>
<%= Html.PasswordFor(m => m.Password, new { @class = "inputbox", @tabindex = "5", @id = "password" })%><%= Html.ValidationMessageFor(m => m.Password, "*")%>
</p>
<p class="remember">
<input id="signin_submit" value="Sign in" tabindex="6" type="submit"/>
<%= Html.CheckBoxFor(m => m.RememberMe, new { @class = "inputbox", @tabindex = "7", @id = "rememberme" })%>
<%= Html.LabelFor(m => m.RememberMe) %>
<p class="forgot"> <a href="#" id="forgot_password_link" title="Click here to reset your password.">Forgot your password?</a> </p>
<p class="forgot-username"> <a href="#" id="forgot_username_link" title="Fogot your login name? We can help with that">Forgot your username?</a> </p>
</p>
<%= Html.ValidationSummaryJQuery("Please fix the following errors.", new Dictionary<string, object> { { "id", "valLogOnContainer" } })%>
<% } %>
</fieldset>
登录表单加载到主页上
<% Html.RenderPartial("LogonControl");%>
不确定这是否与此有任何关系,但我想我会提到它。
编辑:登录表单的加载类似于 Twitter 登录,单击链接,表单将在 jQuery 和 CSS 的帮助下加载
最佳答案
您的操作签名将如下所示:
public virtual JsonResult ActionName()
{
var abcObj = new ABC{a=1,b=2};
return Json(abcObj);
}
关于asp.net-mvc - 将 Json 对象从 Controller 操作返回到 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4564341/
我最后一次使用C++是在它无法被管理之前。不过最近,我从 Java 回来,看到现在可以管理 C++ 了! 没过多久我就意识到gcnew 和^ 的用途。但是,我对容器有点卡住了。 如何创建一个容器,其元
我离开 Microsoft 堆栈已有一段时间了,专注于 Linux、开源内容和 PHP 中的 Web 开发。我曾经在 Dev Studio(所有 C 和 C++)中在 Windows 上进行一些桌面应
在我的程序中有两个 View Controller 。第一个有表格 View 。当我单击一个单元格时,相关的炎症会显示在第二个 View Controller 中。它运作良好。 当我返回到第一个 Vi
我使用 AVAssetWriter 和 CMSampleBuffer 数据(来自视频、音频输入)录制视频(.mp4 文件)。 在录制时我想处理帧,我正在将 CMSampleBuffer 转换为 CII
在 python 中有两种不同的离开循环的选项。 continue 将您带回到循环的开头,break 就像一个电灯开关,它会在脚本运行的剩余时间内切断循环。我的问题是我有一个 while True 循
我是 Git 的新手,我正试图恢复到 SourceTree 中的先前提交。我右键单击要还原到的提交,然后单击 checkout 。它给了我一个提示,说我的工作副本将成为一个独立的头。这是什么意思,这是
所以我决定在离开几年后,为了我的一些个人项目重新使用 Ruby on Rails。我想知道的是,找出 Rails 中的新功能的最佳资源是什么?自从 1.2 是新的以来,我什至没有真正接触过 Rails
我的项目有两个部分。第一部分是在 Storyboard中制作的,第二部分是 SKView。如何从 SKView 中的第二部分返回到主 UIView? 最佳答案 创建自定义 ViewController
所以我在大约四次提交前对我的项目做了一个糟糕的改变。我了解到我可以恢复到之前描述的状态 here ,并通过依次检查以前的提交(并在我的设备上测试它们),我已经确定了问题发生的位置。 现在我想回到坏改变
我想知道,在 Canvas 的 commandAction 方法中,如何让我的命令按钮回到 MIDlet 的开始? (基本上重新开始)。 当按键触发时,我将它带到一个新的列表页面。在该页面上,我有一个
我想知道是否可以使用 intro.js 返回到下一行。我尝试了\n 和其他类似的东西,但它们中的任何一个都有效并且不可能在文档中找到类似的东西。有谁知道这是否可能? 最佳答案 正确的做法是像这样使用
这是关于我发现我的应用程序面临的一个反复出现的问题,它与使用几个 DialogFragment 相关。我主要针对平台级别 8 设备,因此要使用 DialogFragments,我必须使用兼容性库。 每
我有一个 uiview 的问题,它放置在 Storyboard的一个位置,在应用程序启动后,我将 uiview 移动到第二个位置,并使用代码中的按钮进行动画处理。 int alpha = -212;
我有 Controller B,它使用委托(delegate)模式将数据发送回 Controller A,但由于某种原因我的 segue 没有触发。 是否有什么东西阻止我的 segue 被触发?我将如
我已经找到了处理除我需要的之外的所有内容的解决方案。这是场景 就像在 GMail 中一样 - 主要内容呈现在 iframe 中。单击主页上的链接会指向 iframe。这效果很好,而且无缝。此时,如果我
我有一个 RCP 程序,带有需要登录的启动屏幕。 我想制作一个注销按钮。通过单击此按钮,用户应该返回到初始屏幕,因此他必须重新登录.. 这可能吗? 提前致谢。 最佳答案 如果您使用org.eclips
我有一个数据框: df = pd.DataFrame({'Section': [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6],
是否可以将元素 $("p") 返回到应用 mouseenter() 方法之前的确切颜色?或者我是否需要知道 mouseenter() 之前的颜色,然后使用 mouseleave() 应用该颜色?我希望
在 Matlab R2016b 中,显示某些数据类型的变量会显示有关该类型的信息。当通过不带最终分号键入变量来显示变量时会发生这种情况(使用 disp 函数时不会发生这种情况)。 比较例如: Matl
是否可以告诉 RSpec::Mocks 为一组值 stub 一个方法,否则回退到原始方法?例如: File.stub(:exist?).with(/txt/).and_return(true) Fil
我是一名优秀的程序员,十分优秀!