首页 \ 问答 \ 在asp.net mvc中使用ajax进行更新(Update using ajax in asp.net mvc)

在asp.net mvc中使用ajax进行更新(Update using ajax in asp.net mvc)

嗨,有人可以告诉我这个问题,以及如何解决它。

我正在尝试使用ajax更新页面的一部分,我正在使用新的mvc项目附带的基本代码。

登录页面包含:

 <span id="error"/>
@using (Ajax.BeginForm("LogOn", "Account", new AjaxOptions { UpdateTargetId="error"})) {
    <div>
        <fieldset>
            <legend>Account Information</legend>

            <div class="editor-label">
                @Html.LabelFor(m => m.UserName)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.UserName)
                @Html.ValidationMessageFor(m => m.UserName)
            </div>

            <div class="editor-label">
                @Html.LabelFor(m => m.Password)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(m => m.Password)
                @Html.ValidationMessageFor(m => m.Password)
            </div>

            <div class="editor-label">
                @Html.CheckBoxFor(m => m.RememberMe)
                @Html.LabelFor(m => m.RememberMe)
            </div>

            <p>
                    <input type="submit" value="Log On" />
            </p>
        </fieldset>
    </div>
}

和控制器一样:

        [HttpPost]
        public string LogOn(LogOnModel model, string returnUrl)
        {

            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                         Redirect(returnUrl);
                    }
                    else
                    {
                         RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            return "The user name or password provided is incorrect.";
        }

基本上我所做的就是将登录表单嵌入到模态弹出窗口中。 如果输入的用户凭据失败,我希望错误显示在模态弹出窗口内,而不是转到另一个页面。

上面的代码只是创建一个空白页面,文本“提供的用户名或密码不正确。”...我需要它显示在模态对话框(jQuery)中。


Hi can someone tell me the problem with this please, and how to fix it.

I'm trying to update part of the page using ajax, I'm using the basic code that comes with a new mvc project.

The logon page has this:

 <span id="error"/>
@using (Ajax.BeginForm("LogOn", "Account", new AjaxOptions { UpdateTargetId="error"})) {
    <div>
        <fieldset>
            <legend>Account Information</legend>

            <div class="editor-label">
                @Html.LabelFor(m => m.UserName)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.UserName)
                @Html.ValidationMessageFor(m => m.UserName)
            </div>

            <div class="editor-label">
                @Html.LabelFor(m => m.Password)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(m => m.Password)
                @Html.ValidationMessageFor(m => m.Password)
            </div>

            <div class="editor-label">
                @Html.CheckBoxFor(m => m.RememberMe)
                @Html.LabelFor(m => m.RememberMe)
            </div>

            <p>
                    <input type="submit" value="Log On" />
            </p>
        </fieldset>
    </div>
}

and the controller like so:

        [HttpPost]
        public string LogOn(LogOnModel model, string returnUrl)
        {

            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                         Redirect(returnUrl);
                    }
                    else
                    {
                         RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            return "The user name or password provided is incorrect.";
        }

Basically what I have done is embeded the login form into a modal popup. if the entered user credentials fail I want the error to be displayed inside the modal popup, not go off to another page.

The above code is just creating a blank page with the text "The user name or password provided is incorrect."...I need it to be displayed in the modal dialog (jQuery).


原文:https://stackoverflow.com/questions/4491561
更新时间:2023-03-15 06:03

最满意答案

试试这个HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="css/myCustom.css">
    <title>Test</title>
</head>
    <body>
    <div calss="row-header">Header Content</div>
    <div class="row-content">Row Content</div>
    <div class="jumbotron"><p><a class="btn btn-lg btn-primary" href="#fork">Fork this fiddle</a></div>
    <address>Address</address>

    <div class="custom">
            <p>Put me to the right on the browser</p>
    </div>
    <div class="row-footer">Footer Content</div>
    <!--scripts at the bottom-->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <!--//scripts-->
    </body>
</html>

并为您的CSS

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0px;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
.custom {
    float: right;
} 
.row-header {
margin:0px auto;
padding:0px auto;
}

.row-content {
margin:0px auto;
padding:50px 0px 50px 0px;
border-bottom:1px ridge;
min-height:400px;
}

.row-footer {
#backgroud-color:#AfAfAf;
background-color: #afafaf;
margin:0px auto;
padding:20px 0px 20px 0px;
}

.jumbotron {
padding:70px 30px 70px 30px;
margin:0px auto;
#backgroud:#7986CB;
background: #7986CB;
color:floralwhite;
}

address {
font-size:80%;
margin:0px;
color:#0f0f0f;
}

这应该对你有帮助。 将代码复制并粘贴到新文件上并进行测试。 我希望这能帮到您。


Try this for your HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="css/myCustom.css">
    <title>Test</title>
</head>
    <body>
    <div calss="row-header">Header Content</div>
    <div class="row-content">Row Content</div>
    <div class="jumbotron"><p><a class="btn btn-lg btn-primary" href="#fork">Fork this fiddle</a></div>
    <address>Address</address>

    <div class="custom">
            <p>Put me to the right on the browser</p>
    </div>
    <div class="row-footer">Footer Content</div>
    <!--scripts at the bottom-->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <!--//scripts-->
    </body>
</html>

and for your CSS

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0px;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
.custom {
    float: right;
} 
.row-header {
margin:0px auto;
padding:0px auto;
}

.row-content {
margin:0px auto;
padding:50px 0px 50px 0px;
border-bottom:1px ridge;
min-height:400px;
}

.row-footer {
#backgroud-color:#AfAfAf;
background-color: #afafaf;
margin:0px auto;
padding:20px 0px 20px 0px;
}

.jumbotron {
padding:70px 30px 70px 30px;
margin:0px auto;
#backgroud:#7986CB;
background: #7986CB;
color:floralwhite;
}

address {
font-size:80%;
margin:0px;
color:#0f0f0f;
}

This should help you. Copy and paste the code on new file and test it. I hope this will help you.

相关问答

更多
  • 随着最近发布的引导3 ,并且字形被合并回主引导报告, Bootstrap CDN现在提供包括Glyphicons的完整的Bootstrap 3.0 css 。 引导css引用是您需要包括的:Glyphicons及其依赖关系位于CDN站点上的相对路径上,并在bootstrap.min.css中引用。 在html中: 在c ...
  • 尝试将标签更改为
    您只需使用wp_enqueue_style加载这些文件即可。 这是一个你可以从中得到一个想法的例子。 function enqueue_my_scripts() { wp_enqueue_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', array('jquery'), '1.9.1', true); // we need the jquery library for bootsrap js to ...
  • 主题是它可选的。 它作为包含核心文件后如何进行主题引导的示例。 所以你想要包括 核心css, 来自cdnjs或google cdn的jQuery 核心js 然后拥有您自己的本地存储的css文件,其中包含您的更改,该文件将与head部分中的主题位于同一位置。 The theme is as it says optional. It serves as an example of how to theme bootstrap after including the core files. So you want ...
  • 我所做的是下载Bootstrap的源代码并为我的定制和覆盖创建一个LESS文件。 我在加载Bootstrap变量LESS后直接加载,然后编译成CSS。 这使我可以在单独的LESS文件中快速制作模组,并编译可以升级而不覆盖我的任何更改的基础Bootstrap。 Bootstrap确实有自己的grunt文件,如果你要使用grunt进行编译,我会这样做。 您可以托管CloudFlare CDN之类的东西。 What I do is download the source for Bootstrap and cre ...
  • 您的网址错误。 您可以将其插入浏览器以查看它的位置。 你: http://netdna.bootstrapcdn.com/twitter-bootstrap/3.0.3/css/bootstrap-combined.min.css 正确一个: http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css 为确保您拥有正确的,请始终从此处获取: http : //getbootstrap.com/getting-started/ ...
  • 创建一个名为custom.css的新文件,并在CDN版本之后将其包含在 。
    我发现的最佳解决方案是将版本标记更改为url的开头,并使用url rewrite来处理请求。 因此,如果我曾经有过: http://website/Content/Images/1.png?123456 这将成为: http://website/123456/Content/Images/1.png 请注意,我使用url rewrite按顺序处理请求,以便http://website/123456/Content/Images/1.png实际上将从http://website/Content/Image ...
  • 试试这个HTML
    (因为这已被拒绝,所以无法帮助;我猜你的问题不适用于逻辑或最佳实践) 基本上你不能简单地改变它,因为CDN使用不同的Domain / Subdomin,命名约定和结构。 但是,你可以试试这个; 假设您的Web服务器可以使用.htaccess ,和 假设CDN将具有相同的文件夹结构和名称。 ::尝试将所有图像/资源请求重定向到CDN。 RewriteRule ([^.]+\.(jpe?g|gif|bmp|png|mp4|css|js))$ http://www.cdn-url.com/$1 [R=301,L, ...

相关文章

更多

最新问答

更多
  • 在开发React应用程序时编译/转换代码(Compile/transpile code while developing React app)
  • 将MultiPoint序列化为GeoJSON文件(Serialize MultiPoint to GeoJSON file)
  • 将字符串截断为特定数量的字符,忽略HTML(Truncate string to certain amount of characters, ignoring HTML)
  • Sqlserver监视时间的变化(Sqlserver watch for time change)
  • Srcset属性 - 最大宽度问题(Srcset attribute - max-width issue)
  • 如何验证数据库中是否存在记录?(How to verify existence of a record in database?)
  • SQL JOIN来自不同表的行具有相同的值(SQL JOIN row from different table with the same values)
  • NSTextField - 使用KVO进行输入验证?(NSTextField - Input validation with KVO?)
  • 在Javascript中,如何检查数组是否有重复值?(In Javascript, how do I check if an array has duplicate values? [duplicate])
  • 获取过滤器从spark数据帧中删除的行的示例(Get examples for rows that are removed by a filter from a spark dataframe)
  • 如果Shape在屏幕外,是否执行Graphics2D.draw?(Is Graphics2D.draw performed if the Shape is offscreen?)
  • 如果没有头文件,如何定义静态成员?(How to define a static member in case there is not header file?)
  • NSLocalizedStringFromTableInBundle:没有获取key的值(NSLocalizedStringFromTableInBundle : not getting values for key)
  • Google Cloud Messanger,“比预期的更多”(Google Cloud Messanger, “More acks than expected”)
  • HorizontalScrollView不起作用(HorizontalScrollView not working)
  • 关闭所有表单后退出应用程序(Quit Application when all forms is closed)
  • 玉林哪个会计培训学校有周末上课的!
  • java的。(java. Unique identifier for each visitor. How better generated?)
  • 希望大家告诉我学java编程的方法?
  • 在GAS嵌入式环境中通过Javascript刷新HTML文档(Refresh HTML Document via Javascript in a GAS Embedded Environment)
  • 当我在另一个类中调用它时,setText不起作用(setText does not work when I call it in another class)
  • 无法在静态字段中设置变量值(Can't Set variable value in Static Field)
  • IE9布局错误 - 在早期的IE版本中很好(IE9 Layout Bug - fine in earlier IE versions)
  • 按钮命令上的WPF新DataGrid行参数为NULL(WPF New DataGrid Row Parameter NULL on Button Command)
  • Wordpress上的CSS配置(CSS configuration on Wordpress )
  • 关于OpenGL设置的问题以及在窗口中绘制掩码的问题(Questions about OpenGL Settings and drawing over a mask in a window)
  • Matlab编码器fzero功能(Matlab coder fzero function)
  • Autodesk Maya,C ++和OpenGL渲染引擎(Autodesk Maya, C++ and OpenGL rendering engine)
  • 选择记录字段包含另一个字段的最大值(Select field of record contains max of another field)
  • 可选参数在Swashbuckle.AspNetCore中导致null异常(Optional parameter causes null exception in Swashbuckle.AspNetCore)