小编Gri*_*zly的帖子

将 List<int> 从 actionlink 传递到控制器方法

在我的控制器中,我有这个:

ViewBag.lstIWantToSend= lstApps.Select(x => x.ID).ToList();  // creates a List<int> and is being populated correctly
Run Code Online (Sandbox Code Playgroud)

我想将该列表传递给另一个控制器..所以在我看来我有:

@Html.ActionLink(count, "ActionName", new { lstApps = ViewBag.lstIWantToSend }, null)
Run Code Online (Sandbox Code Playgroud)

控制器中的方法:

public ActionResult ActionName(List<int> lstApps)   // lstApps is always null
Run Code Online (Sandbox Code Playgroud)

有没有办法将整数列表作为路由值发送到控制器方法?

asp.net-mvc asp.net-mvc-routing html.actionlink

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

如何从字符串jQuery中删除多个空格

我有一个包含3列的Excel电子表格.

    1st        |    2nd    |    3rd 
----------------------------------------
  xxxxxxxx           x        xxxxxxxx
Run Code Online (Sandbox Code Playgroud)

当我复制所有这三个单元格并将它们粘贴到我的文本框中时,我得到一个看起来像这样的值:

在此输入图像描述

我需要消除空间,但我研究的是不起作用.

这是我有的:

$(document).ready(function() {
    $("#MyTextBox").blur(function() {
        var myValue = $(this).val();
        alert(myValue);
        var test = myValue.replace(' ', '');
        alert(test);
        $("#MyTextBox").val(test);

    });
});
Run Code Online (Sandbox Code Playgroud)

当我发出警报时,test它看起来与原始图像完全相同,MyTextBox并且没有替换值.

我有一个JSFiddle,我试图复制该问题,但在这个例子中,只有第一个空格被替换,但新值填充到文本框中.

我究竟做错了什么?

任何帮助表示赞赏.

javascript jquery

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

如何将c#中字符串中每个单词的第一个字母大写

我曾尝试研究"可能已经有你答案的问题",但由于大多数问题涉及不同的编程语言,所以他们都没有真正帮助过.

所以关于C#,特别是ASP.NET MVC,在我的Create动作中我有代码来大写字符串中第一个单词的第一个字符,但如果用户输入2个单词,则第二个单词的第一个字符保持小写.

这是我到目前为止控制器中的内容

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ID,text,subcategory")] Activities codeAC)
{
    if (ModelState.IsValid)
    {
        char firstLetter = codeAC.text[0];

        if (char.IsLower(firstLetter))
        {
            codeAC.text = codeAC.text.First().ToString().ToUpper() + String.Join("", codeAC.text.Skip(1));
        }
Run Code Online (Sandbox Code Playgroud)

如何修改它,以便如果用户输入'test test2',保存到数据库中的结果将是'Test Test2',而不是'Test test2'

任何帮助表示赞赏.

c# string char asp.net-mvc-5

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

带 Bootstrap 的 HTML 新行

使用此参考和红色警报选项。这里是:

<div class="alert alert-dismissible alert-danger">
    <button type="button" class="close" data-dismiss="alert">&times;</button>
    <strong>Oh snap!</strong> <a href="#" class="alert-link">Change a few things up</a> and try submitting again.
</div>
Run Code Online (Sandbox Code Playgroud)

在他们的示例中,try之后有一个换行符.. 仅仅是因为宽度吗?

我的版本:

<div class="alert alert-dismissable alert-danger" style="float:right;">
    <button type="button" class="close" data-dissmiss="alert">&times;</button>
    <strong>Leave blank if there is already a Record for today!&#13;&#10; This will auto-calculate based on the previous Record.</strong>
</div>
Run Code Online (Sandbox Code Playgroud)

现在我的没有任何换行符,但我也没有弄乱 CSS .. 但我想知道是否有办法在内<strong>联中放置换行符?我尝试使用this,但我想那是严格用于<textarea>'s 的。

任何帮助表示赞赏。

html css twitter-bootstrap

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

重定向到页面但特定选项卡

我用这个作为我想要做的事情的一个例子.

我有一个标签页.

在我的控制器中,我想重定向到页面,但该页面上的特定选项卡.

现在,当我在该页面上时,将鼠标悬停在选项卡上,链接就是 http://localhost:xxxxx/OInfoes/Details/2#phases

所以在我的控制器中我这样做是为了尝试重新创建相同的链接:

return new RedirectResult(Url.Action("Details", "OInfoes", new { id = phase.OID }) + "#phases");
Run Code Online (Sandbox Code Playgroud)

这给了我正确的链接,但它没有把我放在正确的选项卡上.

我如何让它工作?

标签的我的HTML如下:

<ul class="nav nav-tabs">
    <li class="active"><a href="#oInfo" data-toggle="tab">Information</a></li>
    <li><a href="#reports" data-toggle="tab">Previous Reports</a></li>
    <li><a href="#phases" data-toggle="tab">Previous/Current Phases</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc tabs

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

将数组切成数组

如果我有一个功能:

function sliceArrayIntoGroups(arr, size) {
  var slicedArray = arr.slice(0, size);

  return slicedArray;
}
Run Code Online (Sandbox Code Playgroud)

我正在寻找一个数组并将其切成数组的数组..我该怎么做呢?

所以,如果我有这个:

sliceArrayIntoGroups(["a", "b", "c", "d"], 2);
Run Code Online (Sandbox Code Playgroud)

结果应为:

[["a","b"],["c","d"]]
Run Code Online (Sandbox Code Playgroud)

但是我不知道在切片后如何保存原始数组的第二部分。

任何帮助表示赞赏。

javascript arrays

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

使用 select2 时保留输入验证 CSS 类

在我的表单上,我有一个下拉列表,我在其中使用Select2

这是我的剃须刀:

<div class="form-group">
    @Html.LabelFor(model => model.StateId, htmlAttributes: new { @class = "control-label col-md-4" })
    <div class="col-md-8">
        @Html.DropDownListFor(model => model.StateId, ViewBag.StateName as SelectList, "-- Select State --", new { id = "CreateState", @class = "form-control" })
        @Html.ValidationMessageFor(model => model.StateId, "", new { @class = "text-danger" })
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我正在使用 jQuery Validation 进行客户端验证。

如果我离开下拉列表而没有选择值,那么我会收到一个验证错误,我正在收到该错误,但不是相应的 css 类,该类以红色勾勒出该框的轮廓input-validation-error

这是我得到的:

在此输入图像描述

正如您所看到的,City获得了红色轮廓,而使用 Select2 的 State 则没有,即使两者都获得了验证消息。

当我检查 Razor 代码中渲染的 HTML 时,我在下拉列表中看到以下内容:

<select name="StateId" tabindex="-1" class="form-control select2-hidden-accessible input-validation-error" id="CreateState" aria-hidden="true" …
Run Code Online (Sandbox Code Playgroud)

html css validation jquery-select2

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

jQuery运行时错误:预期的功能

我在我的Web应用程序的Create View中使用jQuery UI Autocomplete

当我在文本框中单击我想要自动完成服务并输入1个字母时,我收到运行时错误:

运行时错误

以下是内置脚本调试器中发生错误的行

发生错误的内置脚本调试器的行

这是我的脚本:

<script type="text/javascript">
$(document).ready(function () {
    $('#Categories').autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "/Activities/AutoCompleteCategory",
                type: "POST",
                dataType: "json",
                data: { term: request.term },
                success: function (data) {
                    response($.map(data, function (item) {
                        return { label: item.subcategory, value: item.subcategory };
                    }))
                }
            })
        },
        messages: {
            noResults: "", results: ""
        }
    });
})
</script>
Run Code Online (Sandbox Code Playgroud)

这是我的控制器:

public JsonResult AutoCompleteCategory(string term)
{
    var result = (from r in db.Activities
                  where r.subcategory.ToUpper().Contains(term.ToUpper())
                  select new …
Run Code Online (Sandbox Code Playgroud)

c# jquery runtime-error asp.net-mvc-5

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

提高生成列表的性能

我有一个由413个对象组成的列表.现在,我正在创建一个基于这些对象的新列表以导出到Excel.

lstDailySummary = (List<DailySummary>)Session["Paging"];

List<ExportExcel> lstExportedExcel = lstDailySummary
    .Select(x => new ExportExcel
    {
        PropertyOne = x.ACInfo.RegNumber,
        PropertyTwo = db.MyTable.Find(x.NavProperty.subcategoryID).Text,
        PropertyThree = x.NavProperty.text,
        PropertyFour = (!string.IsNullOrWhiteSpace(x.Agcy.ToString())) ? x.codeAgcy.location : " ",
        PropertyFive = x.EventLocation,
        PropertySix = x.codeCounty.county,
        PropSeven = x.Flight,
        PropEight = x.FlightDay.ToString("MM/dd/yyyy HH:mm"),
        PropNine = x.IncidentNumber,
        PropTen = x.codeLocation.Location,
        PropEleven = x.Summary,
        PropTwelve = x.Total,
        PropThirteen = x.ATime
    })
    .ToList();
Run Code Online (Sandbox Code Playgroud)

在调试模式下,使用VS 2017,我看到这需要47到52秒,因此,在一分钟之内执行.

是否有更快的方法来使用而不是.Select在这种情况下?

c# linq performance entity-framework

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

字符串到日期时间转换"M/dd/yyyy"

我有一个日期字符串 4/30/2016

我尝试使用以下代码转换它:

DateTime dt = DateTime.Parse(date);

我收到了错误

该字符串未被识别为有效的DateTime.从索引0开始有一个未知单词.

你能帮帮我怎样才能解决这个问题?为什么会发生这种错误?

c# asp.net

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