Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# asp mvc格式的timespan(mm:ss)文本框,用于与引导计时器一起使用_C#_Jquery_Asp.net Mvc_Twitter Bootstrap_Formatting - Fatal编程技术网

C# asp mvc格式的timespan(mm:ss)文本框,用于与引导计时器一起使用

C# asp mvc格式的timespan(mm:ss)文本框,用于与引导计时器一起使用,c#,jquery,asp.net-mvc,twitter-bootstrap,formatting,C#,Jquery,Asp.net Mvc,Twitter Bootstrap,Formatting,我读过好几篇有类似问题的帖子,但我还是不能让它正常工作。我的问题是将两个timespan属性格式化为mm:ss,并让它们正确地与引导数据采集器一起工作 模型属性:(不确定是否正确) 观点: @Html.EditorFor(model => model.QueueModel.AgentHoldoffTime, new { htmlAttributes = new { @class = "form-control timepicker-holdOffTime" } }) @Html.Edi

我读过好几篇有类似问题的帖子,但我还是不能让它正常工作。我的问题是将两个timespan属性格式化为mm:ss,并让它们正确地与引导数据采集器一起工作

模型属性:(不确定是否正确)

观点:

@Html.EditorFor(model => model.QueueModel.AgentHoldoffTime, new { htmlAttributes = 
new { @class = "form-control timepicker-holdOffTime" } })

@Html.EditorFor(model => model.QueueModel.AgentAlertTime, new { htmlAttributes = 
new { @class = "form-control timepicker-alertTime" } })
JS:

现在,当视图呈现时,一个文本框将显示
00:17
时间(7)列,其值为
00:00:17.0000000
。一切似乎都很好,但当我提交
01:00
时,它会保存为
01:00:00.0000000
而不是
00:01:00.0000000
?我可能错过了一些简单的东西,但我想不出来


提前感谢。

< P>当你使用“EddioRoFor”框架尝试为数据类型渲染最好的HTML元素时,最好是<代码> <代码>,因为我知道你需要句柄秒,但是默认情况下这个输入不考虑秒,你需要用属性<代码>步骤= 1 < /代码>“强制”。现在,如果您使用“EditorFor”,它不允许您设置属性,或者至少我还没有找到如何设置属性,那么请将其更改为“TextBoxFor”:

@Html.TextBoxFor(model => model.AgentHoldoffTime, new
                {
                    @class = "form-control timepicker-holdOffTime",
                    type = "time",
                    step = 1
                })

我希望此帮助指定格式对我有用:

@Html.TextBoxFor(m => Model.AgentHoldoffTime,
    "{0:hh\\:mm}",
    new { 
       @class = "form-control",
       placeholder = "hh:mm",
})
此签名:

//
// Summary:
//     Returns a text input element.
//
// Parameters:
//   htmlHelper:
//     The HTML helper instance that this method extends.
//
//   expression:
//     An expression that identifies the object that contains the properties to display.
//
//   format:
//     A string that is used to format the input.
//
//   htmlAttributes:
//     An object that contains the HTML attributes to set for the element.
//
// Type parameters:
//   TModel:
//     The type of the model.
//
//   TProperty:
//     The type of the value.
//
// Returns:
//     An input element whose type attribute is set to "text".
public static MvcHtmlString TextBoxFor<TModel, TProperty>(
                                this HtmlHelper<TModel> htmlHelper,
                                Expression<Func<TModel, TProperty>> expression,
                                string format,
                                object htmlAttributes);
//
//总结:
//返回一个文本输入元素。
//
//参数:
//htmlHelper:
//此方法扩展的HTML帮助程序实例。
//
//表达方式:
//一个表达式,用于标识包含要显示的属性的对象。
//
//格式:
//用于设置输入格式的字符串。
//
//HTMLAT贡品:
//包含要为元素设置的HTML属性的对象。
//
//类型参数:
//TModel:
//模型的类型。
//
//t财产:
//值的类型。
//
//返回:
//类型属性设置为“text”的输入元素。
公共静态MvcHtmlString TextBoxFor(
这个HtmlHelper HtmlHelper,
表情表情,
字符串格式,
对象(属性);

应该是
01:00
而不是
01.00
?@ChrisPratt当我在文本框中输入
01:00
(一分钟)时,值将保留为
01:00:00.0000000
(一小时)。这就是问题所在,不确定是格式化问题还是日期选择器问题。我不知道
的区别,我指的是你的问题。在最后一段你写了
01.00
。我仔细检查了一下,这实际上是一个打字错误,否则肯定会有问题。@ChrisPratt谢谢你注意到这一点
01.00
是一个打字错误,我的意思是写
01:00
@Html.TextBoxFor(m => Model.AgentHoldoffTime,
    "{0:hh\\:mm}",
    new { 
       @class = "form-control",
       placeholder = "hh:mm",
})
//
// Summary:
//     Returns a text input element.
//
// Parameters:
//   htmlHelper:
//     The HTML helper instance that this method extends.
//
//   expression:
//     An expression that identifies the object that contains the properties to display.
//
//   format:
//     A string that is used to format the input.
//
//   htmlAttributes:
//     An object that contains the HTML attributes to set for the element.
//
// Type parameters:
//   TModel:
//     The type of the model.
//
//   TProperty:
//     The type of the value.
//
// Returns:
//     An input element whose type attribute is set to "text".
public static MvcHtmlString TextBoxFor<TModel, TProperty>(
                                this HtmlHelper<TModel> htmlHelper,
                                Expression<Func<TModel, TProperty>> expression,
                                string format,
                                object htmlAttributes);