小编Chu*_*ris的帖子

Ajax.BeginForm不会调用onSuccess

在ASP.NET MVC 3应用程序中,我使用Ajax.BeginForm将写入的文本发布到控制器.

@using (Ajax.BeginForm("Post", "Forum", new {threadId = Model.Thread.Id  }, new AjaxOptions { OnSuccess = "PostReply" }))
{
    <div id="reply-area">
        <h3 style="border-bottom:1px solid black">POST REPLY</h3>

        <span id="post-error" class="error-message"></span>
        <textarea rows="1" cols="1" id="post-textarea" name="Content">    </textarea>

         <input type="submit" class="button" value="Submit"/>

     </div>
}
Run Code Online (Sandbox Code Playgroud)

在控制器中我有

 [HttpPost]
 public ActionResult Post(int threadId,PostModel model)
 {
     bool Success = false;
     if (ModelState.IsValid)
     {
        Success=Unit.ForumFacade.CreatePost(Unit.ForumFacade.GetThreadByID(threadId), model.Content,  CurrentUserId);
        if (Success == true) return View("PostSuccess");
    }

    return Json("fsdfds");
}
Run Code Online (Sandbox Code Playgroud)

在javascript中我有这个

function PostReply(isRequestSuccessed) {
    alert("asdasd");
    if (isRequestSuccessed==false) {
        $("#post-error").html("Please Try Again"); …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc jquery asp.net-ajax asp.net-mvc-3

5
推荐指数
1
解决办法
2万
查看次数

CSS对齐问题

如何使我的注册字段成为这样的

在此输入图像描述

我怎样才能通过CSS实现这一目标?我的意思是,我的文本框应该从标签的末尾到页面的末尾对齐......

编辑

这是我的观点部分

<div id="member-search">

<h5>Last Name:</h5>
@Html.TextBox("member-last-name")
</div>
<div>
<h5>Pass:</h5>
@Html.TextBox("member-pass")
</div>

<input type="submit" value="Search" class="button"/>
</div>
Run Code Online (Sandbox Code Playgroud)

在CSS中我尝试了很多,但没有成功.宽度:自动没有帮助,我找不到解决方案.感谢帮助.

html css asp.net-mvc jquery asp.net-mvc-3

5
推荐指数
1
解决办法
185
查看次数

将Jquery分页和历史插件结合使用的最有效方法

在我的ASP.NET MVC 3应用程序中,我想使用Jquery的pagination插件来创建我的论坛...

所以我想,用Ajax做所有的页面更改,并希望使用history插件来处理浏览器的后退和下一个按钮......

什么是最有效的javascript/jquery代码?

我在几个月前写过这段代码,但现在看来我很难看.检查一下

$(document).ready(function () {

         $.history.init(function (hash) {

            if (hash != "") {
                NavigateToPage(hash.substring(0,hash.indexOf("page")),hash.substring(hash.lastIndexOf("_")+1));
            } else {
                    if(firstTimeOpen==true){
                        firstTimeOpen=false;
                    }
                    else
                    {
                        window.location.replace("/Forum");
                    }
            }

        });

        $(".more-button").click(function () {

            currentForumId=$("#pagination-td").parent().prev().attr("id").substring(5);
            $.history.load($(this).parents("tr").attr("id").substring(5)+"page_1");

            });


        });


    function NavigateToPage(forumId,page) {
            lastForumId=currentForumId;
            currentForumId=forumId;
            var elem=$("#forum"+forumId);
            var elemStr="#forum"+forumId;
            if($("#pagination-td").parent().prev().attr("id").substring(5)!=forumId)
            {
            forumChanged=true;
            MakeChanges(elem,page);
            }
            else
            {
                if($(".pagination").html()==null)
                {
                    if(elem.find("a").attr("id")>@MyProject.Constants.THREAD_COUNT)
                    {
                   $("#pagination-td").pagination(elem.find("a").attr("id"), {
                   items_per_page: @MyProject.Constants.THREAD_COUNT,
                    callback: handlePaginationClick
                    });
                    }
                }
            }


          $.get('/Forum/ForumThreads', { id: forumId, beginNumber: page - 1, count: …
Run Code Online (Sandbox Code Playgroud)

javascript jquery history pagination asp.net-mvc-3

5
推荐指数
1
解决办法
1273
查看次数

Google Chrome中的表格行的CSS背景问题

我有一张桌子,我有这个

</tr>
<tr class="table-top-background" >
<td class="thread-pic" ></td>
<td class="thread-top-middle"  colspan="2" >Threads</td>
<td class="thread-information">Last Post</td>
</tr>
Run Code Online (Sandbox Code Playgroud)

所以我想给我的tr提供背景图片,所以我把它放了

    .table-top-background

    {
        background:url('/img/design/extra-large-back.png') no-repeat;
        position:relative;
        color:White;
        height:31px;
    }

    .thread-pic
{
   width:30px;
}

.thread-information
{
    width:280px;
}

.thread-top-middle
{
    width:418px;
}
Run Code Online (Sandbox Code Playgroud)

问题是,在所有浏览器中,谷歌Chrome都可以.在谷歌浏览器中,似乎我给背景不是tr,而是给所有td ...它为每个td重复相同的背景.

它在IE7中是相同的,但在stackoverflow问题之一中,我读到了解决这个问题position:relative并且它有所帮助.但我没有找到Chrome的任何solutuin.我也尝试给这样的tr css

.table-top-background

{
    background:url('/img/design/extra-large-back.png') no-repeat 0% 100%;
    display:block;
    position:relative;
    color:White;
    height:31px;
    width:728px;
}
Run Code Online (Sandbox Code Playgroud)

但是它改变了我的所有桌面设计......当时这个标题行的td中的文本不在那个地方,而且我表中的所有其他第一个td与我的标题tr的大小相同.这似乎真的很有趣.

我也试着给予display:inline-table代替display:block而且它也没有帮助我......那个问题的解决方案是什么?

编辑:在Safari中也存在同样的问题,因此它是webkit问题.

html css google-chrome css-tables

5
推荐指数
1
解决办法
4693
查看次数

设置可选的禁用属性

我想禁用表单中的所有字段,这些字段在加载页面时具有值.例如在这

<td>@Html.TextBoxFor(m => m.PracticeName, new { style = "width:100%", disabled = Model.PracticeName == String.Empty ? "Something Here" : "disabled" })</td>
Run Code Online (Sandbox Code Playgroud)

我想写内联这样的东西.我不想使用if-else并使我的代码更大.使用javascript/jquery也不受欢迎.

我试着编写false/true,但是1.它可能不是跨浏览器2.Mvc将其解析为字符串,如"True"和"False".那我该怎么办呢?

PS我使用ASP.NET MVC 3 :)

html asp.net-mvc asp.net-mvc-3

5
推荐指数
1
解决办法
975
查看次数

SQL Server主数据库

当我使用SQL Server 2008时,我不小心对SQL服务器主数据库运行了很多脚本.

这可能有问题吗?这样做会产生哪些问题?

sql sql-server sql-server-2008

4
推荐指数
1
解决办法
928
查看次数

Firefox中的日期问题

我想在我的页面中解析日期到Javascript的Date.

所以我在我的页面中有这个

<span>01-07-2012 01:04 PM</span>
Run Code Online (Sandbox Code Playgroud)

我有Javascript代码解析这个值到目前为止

var tagText = $(this).html();
var givenDate = new Date(tagText);
alert(givenDate);
Run Code Online (Sandbox Code Playgroud)

这是我在不同的浏览器中得到的

IE:

UTC 1月7日13:04:00 UTC + 0400 2012

铬:

星期六07七月2012 13:04:00 GMT +0400(高加索标准时间)

火狐:

失效日期

为什么Firefox无法识别我的约会?我必须改变什么才能使它适用于所有主流浏览器?

这是jsfiddle http://jsfiddle.net/mgER5/1/

javascript firefox cross-browser

4
推荐指数
1
解决办法
2457
查看次数

从String中删除空格

我有很多看起来像这样的字符串:

current            affairs
Run Code Online (Sandbox Code Playgroud)

我想让字符串成为:

current affairs
Run Code Online (Sandbox Code Playgroud)

我尝试使用,Trim()但它不会做这个工作

c#

4
推荐指数
2
解决办法
248
查看次数

创建像pageflakes这样的东西

有没有人知道一个教程,可以让你为你的网站创建像pageflakes.com这样的东西?或许在jquery?

javascript jquery

3
推荐指数
1
解决办法
874
查看次数

客户端验证在int字段,IE浏览器上的DropDownList失败

赢得7 Ult,IE9.以下列表通过视图包传递到视图中的DropDownList.

List<int> test1ddl = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Run Code Online (Sandbox Code Playgroud)

它工作正常几天然后突然开始失败客户端验证时,"发布的字段Test1必须是一个数字"(它永远不会到达POST操作).我传递List或List时失败.如果我用编辑器替换DropDownList,则POST工作并更新字段.

我在计算机上做的唯一事情是重新安装IIS,这是在使用IIS Express进行调试时发生的.

当我将备份恢复到计算机时,问题就消失了.我随后使用此DropDownList设置将应用程序部署到Internet,并且在XP上使用IE 8时出现"必须是数字"错误.Chrome和FireFox工作正常.它也适用于Win7上的IE9.

我还发现,我甚至不必单击"保存",只需单击浏览器窗口使其失焦,在选择DropDownList后,会显示验证错误.字符串和int List都会发生这种情况.使用部署的Web App在XP上使用IE8也会出现这种情况.

我恢复了失败的Win7配置的备份,然后在IIS Express上使用IE9再次调试失败.如果我在此配置中使用IE9打开已部署的站点,它可以正常工作.(我无法使用IIS Express测试Chrome,因为在失败的配置中,VS2010将不使用默认浏览器,只使用IE.如果有人知道为什么会发生这种情况,这是一个单独的问题).

在这一点上,我认为实际代码没有任何问题,但它似乎是一个浏览器问题.由于XP和IE8仍然是一个非常常见的桌面设置,我需要让它工作.

我的问题是为什么有些浏览器会生成验证错误?

谢谢,乔

如果您创建新的MVC3 Web App并添加这些文件,则可以重新创建我的ddlTestDB应用程序.

Add this to the _Layout.cshtml menu.         <li>@Html.ActionLink("Test", "Index", "Test")</li>

*************** Controller     TestController.cs    **********
using System.Collections.Generic;
using System.Web.Mvc;
using ddltest.Models;
using ddltest.Infrastructure;

namespace ddltest.Controllers
{
  public class TestController : Controller
  {
    ddlTestDb _db = new ddlTestDb();

    public ActionResult Index()
    {
      var model = _db.Tests;
      return …
Run Code Online (Sandbox Code Playgroud)

validation internet-explorer asp.net-mvc-3

3
推荐指数
1
解决办法
2073
查看次数