我创建了 ASP .NET MVC 应用程序。单击按钮时,我调用禁用相同按钮的 JavaScript。之后(按钮的属性只读被禁用)发布操作不会调用。当我删除禁用按钮的 JavaScript 时,一切都很好。这只发生在谷歌浏览器中。
当我在 Firefox 或 Internet Explorer 中尝试相同的示例时,一切都很好。
<script src="../../Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function () {
Enable();
});
function Enable() {
$('#btn').removeAttr('disabled');
$('#btn').removeAttr('readonly');
}
function Disable() {
$('#btn').attr('disabled', 'true');
$('#btn').attr('readonly', 'true');
}
</script>
<h2>Example</h2>
<form>
<input id="btn" type="submit" value="StackOverflow" onclick="Disable()" />
</form>
Run Code Online (Sandbox Code Playgroud) 在我写入数据库的方法中,我处理错误,如下面的代码所示.在catch (DbUpdateException ex)我想重新抛出异常并在最后捕获它catch (Exception ex).
这可能吗,怎么做?下面的代码不会这样做.
using (Entities context = new Entities())
{
try
{
context.Office.Add(office);
retVal = context.SaveChanges();
}
catch (DbUpdateException ex)
{
SqlException innerException = ex.GetBaseException() as SqlException;
if (innerException != null && innerException.Number == (int)SQLErrorCode.DUPLICATE_UNIQUE_CONSTRAINT)
{
throw
new Exception("Error ocurred");
}
//This is momenty where exception is thrown.
else
{
throw ex;
}
}
catch (Exception ex)
{
throw
new Exception("Error");
}
}
Run Code Online (Sandbox Code Playgroud) 我有以下代码.在我的测试planList集合中有150个项目.删除计数为75后,表示从列表中删除了75个项目.为什么在countItems列表之后是150.似乎没有从列表中删除项目.为什么?我如何从列表中删除项目.
...
planList = (IList<UserPlanned>)_jsSerializer.Deserialize(plannedValues,typeof(IList<UserPlanned>));
int count = planList.ToList().RemoveAll(eup => eup.ID <= -1);
int countItems = planList.Count;
...
Run Code Online (Sandbox Code Playgroud)