我是MVC4的新手.这里我添加了ModelState.AddModelError消息,以便在无法执行删除操作时显示.
<td>
<a id="aaa" href="@Url.Action("Delete", "Shopping", new { id = Request.QueryString["UserID"], productid = item.ProductID })" style="text-decoration:none">
<img alt="removeitem" style="vertical-align: middle;" height="17px" src="~/Images/remove.png" title="remove" id="imgRemove" />
</a>
@Html.ValidationMessage("CustomError")
</td>
@Html.ValidationSummary(true)
Run Code Online (Sandbox Code Playgroud)
在我的控制器中
public ActionResult Delete(string id, string productid)
{
int records = DeleteItem(id,productid);
if (records > 0)
{
ModelState.AddModelError("CustomError", "The item is removed from your cart");
return RedirectToAction("Index1", "Shopping");
}
else
{
ModelState.AddModelError(string.Empty,"The item cannot be removed");
return View("Index1");
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,我没有通过视图中的任何模型项来检查模型中的项目,我无法得到ModelState错误消息..
任何建议
我使用更新操作根据@ Html.Textbox的输入进行更新.
@using (Html.BeginForm("Update", "Shopping", new { UserID = Request.QueryString["UserID"] }, FormMethod.Post, new { id = "myForm" }))
{
@Html.ValidationSummary()
@Html.Hidden("id", @Request.QueryString["UserID"] as string)
@Html.Hidden("productid", item.ProductID as string)
@Html.TextBox("Quantity", item.Quantity)
@Html.ValidationMessage("Quantity", "*")
@Html.Hidden("unitrate", item.Rate)
<input type="submit" value="Update" />
}
Run Code Online (Sandbox Code Playgroud)
在我的模型课中
[Required(ErrorMessage = "Quantity is required.")]
[Display(Name = "Quantity")]
[Range(2, 100, ErrorMessage = "There is not enough inventory for the product to fulfill your order.")]
public int? Quantity { get; set; }
Run Code Online (Sandbox Code Playgroud)
问题是当文本框为空时我没有收到验证消息.但是当我使用@ Html.TextBoxFor时
@Html.TextBoxFor(modelItem => item.Quantity)
@Html.ValidationMessageFor(modelitem => item.Quantity)
Run Code Online (Sandbox Code Playgroud)
我收到验证消息.我的更新操作无效. …
参考AjaxControlToolkit,我从MVC创建了一个UI对话框.
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
<link href="../../Content/smoothness/jquery-ui-1.10.2.custom.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery-1.9.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.10.2.custom.min.js" type="text/javascript"></script>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
Run Code Online (Sandbox Code Playgroud)
<h2>jQuery UI Hello World</h2>
<button id="show-dialog">Click to see jQuery UI in Action</button>
<div id="dialog" title="jQuery UI in ASP.NET MVC" >
<p>You now have the power of ASP.NET, the simplicity of client-side scripting with jQuery, and the looks of jQuery UI. Congrats, …Run Code Online (Sandbox Code Playgroud) 我从gridview导出到excel.有没有办法格式化标题文本并将其包装在Excel中?我导出到excel代码为
grdCommon.Font.Size = FontUnit.XSmall;
grdCommon.GridLines = GridLines.Both;
grdCommon.Style["font-family"] = "Arial, Helvetica, sans-serif;";
grdCommon.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
grdCommon.HeaderStyle.ForeColor = System.Drawing.Color.White;
grdCommon.HeaderStyle.BackColor = System.Drawing.Color.FromArgb(80, 124, 209);
grdCommon.HeaderStyle.Font.Size = 8;
grdCommon.HeaderStyle.Width = 30;
Run Code Online (Sandbox Code Playgroud)
我尝试添加如下格式化excel中的标题列.但是excel标题并没有被包裹起来
grdCommon.HeaderRow.Style.Value = "word-break:break-all;word-wrap:break-word";
grdCommon.HeaderRow.Cells[0].Wrap = true;
Run Code Online (Sandbox Code Playgroud)
并修改了这个方法
grdCommon.HeaderRow.Style.Add("background-color", "#FFFFFF"); as
grdCommon.HeaderRow.Style.Add("word-wrap","true");
Run Code Online (Sandbox Code Playgroud)
有什么建议...
我正在使用此代码在 _Layout.cshtml 页面中显示倒数计时器。
但是当我从一个页面移动到另一个页面时,计时器会在新页面加载时再次启动。1.如何在导航到新页面时显示计时器而不重新启动。
2.如何阻止用户刷新页面,使计时器不再启动。
我的布局代码:
<table width="100%">
<tr>
<td width="2%">
<img src="~/Images/philips_new.png" alt="" height="45" width="155" />
</td>
<td width="79%" align="right" class="Text_nocolor">
<span class="Text_nocolor">
@{ Html.RenderAction("GetUserName", "Login");}
</span>
</td>
<td width="4%">
<div id="counter">
</div>
</td>
<td width="4%" class="Text_nocolor" valign="middle">
<a href="@Url.Action("Index", "Login", new { controller = "Login" })">
<img src="~/Images/nome-logout.png" alt="" height="24" width="30" style="border-style: none; cursor: pointer;" /></a>
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
我尝试使用 jquery 插件倒数计时器,但它在 IE 中显示对象不支持此属性错误。
任何建议都会有所帮助。
我需要使用jquery在同一轨道圆圈中旋转多个图像.我更改并延迟了两个图像的时间间隔.问题是图像在几秒钟后重叠.我的代码是
<script type="text/javascript">
var p = 0;
function moveit() {
p += 0.02;
var r = 135;
var xcenter = 500;
var ycenter = 200;
var newLeft = Math.floor(xcenter + (r * Math.cos(p)));
var newTop = Math.floor(ycenter + (r * Math.sin(p)));
$('#friends').animate({
top: newTop,
left: newLeft,
}, 10, function() {
moveit();
$('#friends2').animate({
top: newTop,
left: newLeft,
},15, function() {
moveit();
});
}
$(document).ready(function() {
moveit();
});
</script>
Run Code Online (Sandbox Code Playgroud)
我的css和html源代码是
#friends { position: absolute; }
#friends2 { position: absolute; }
<img src="Images/info.gif" …Run Code Online (Sandbox Code Playgroud) 有没有办法在Export to Excel函数中使用此功能从UniversalSortableDateTimePattern单独获取日期.Excel不接受日期格式..
我需要显示为yyyy-MM-dd.任何建议都会有所帮助吗?我的代码为
dtASalesDrivers.Columns.Add(new System.Data.DataColumn("Start Date", typeof(String)));
DateTime dt = Convert.ToDateTime(txtATrendStartDate.Text);
drASalesDrivers[2] = string.Format("{0:yyyy-MM-dd}", dt);
dtASalesDrivers.Rows.Add(drASalesDrivers);
Run Code Online (Sandbox Code Playgroud)
编辑:
DateTime dt = Convert.ToDateTime(txtATrendStartDate.Text);
drASalesDrivers[2] = string.Format("{0:u}", dt);
Run Code Online (Sandbox Code Playgroud)
这会显示日期和时间.有没有办法只显示日期???
我在_Layout.cshtml页面中传递了一个查询字符串值
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
<li>@Html.ActionLink("Shopping", "Index1", new { controller = "Shopping", UserID = "Admin" })</li>
Run Code Online (Sandbox Code Playgroud)
如何在View Index1.cshtml页面中传递值
<a href="@Url.Action("Delete","Shopping", new { id = Request.QueryString["UserID"] })">
<img alt="removeitem" style="vertical-align: middle;" height="17px" src="~/Images/remove.png" title="remove" />
</a>
Run Code Online (Sandbox Code Playgroud)
我没有在控制器中获取查询字符串值
public ActionResult Delete()
{
string id = Request.QueryString["UserID"];
int records = DeleteItem(id);
if (records > 0)
{
return RedirectToAction("Index", "Shopping");
}
else
{
ModelState.AddModelError("", "Can Not Delete");
return View("Index");
}
}
public int DeleteItem(string id)
{
con.Open();
SqlCommand cmd = new SqlCommand("delete from Cpecial_Shopping_Cart_tbl where …Run Code Online (Sandbox Code Playgroud) 我正在尝试验证文本框,只有在后跟任何字母字符时才允许空格字符.仅插入空格字符时,我的代码失败.我的代码中有什么错误.建议请..
javascript:
function validate() {
var firstname = document.getElementById("FirstName");
var alpha = /^[a-zA-Z\s-, ]+$/;
if (firstname.value == "") {
alert('Please enter Name');
return false;
}
else if (!firstname.value.match(alpha)) {
alert('Invalid ');
return false;
}
else
{
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
视图:
@Html.TextBoxFor(m => m.FirstName, new { @class = "searchbox" })
<button type="submit" onclick="return validate();">Submit</button>
Run Code Online (Sandbox Code Playgroud)
我应用的条件:
例如:Arun Chawla - 条件成功
例如:_ - 条件失败(不应仅允许空格字符)
我已经尝试搜索一个解决方案,该解决方案为日期值提供了正确的周数.
link1,link2,link3
按照上述链接中的方法,但是对于2014年12月30日的日期,我将周数作为53.但它是2015年的第1周.
我尝试了以下方法来获取特定日期的年份周数.
private int GetWeekNumberOfTheYear() {
var currentCulture = CultureInfo.CurrentCulture;
// option 1
var weekNo = currentCulture.Calendar.GetWeekOfYear(DateTime.Now,currentCulture.DateTimeFormat.CalendarWeekRule, currentCulture.DateTimeFormat.FirstDayOfWeek);
// option 2
var weekNo = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
return weekNo; }
Run Code Online (Sandbox Code Playgroud)
上面的方法是否正确,以53号作为周数返回,或者它应该是1?
上面的代码中是否有任何错误.建议请.编辑:
发现许多搜索指定,2014年12月29日至2015年1月4日为2015年第1周.
所以我的困惑是本周必须被视为第53周或第1周.
http://week-number.net/calendar-with-week-numbers-2014.html
http://www.epochconverter.com/date-and-time/weeknumbers-by-year.php
asp.net ×8
c# ×7
asp.net-mvc ×3
jquery ×3
css ×1
cultureinfo ×1
date ×1
date-format ×1
excel ×1
gridview ×1
image ×1
javascript ×1
openxml-sdk ×1
validation ×1