我想创建一个以div为中心的指令.
到目前为止,我有这个代码:
app.directive("setcenter", function () {
return {
scope:{
setcenter: '='
},
link: function (scope, element, attrs) {
scope.$watch('setcenter', function (newValue) {
if (newValue == true) {
var width = element.width();
element.css('position', 'absolute');
element.css('top', '80px');
element.css('left', '50%');
element.css('z-index', '200');
element.css('margin-left', '-' + width / 2 + 'px');
}
});
}
}
});
Run Code Online (Sandbox Code Playgroud)
问题是元素的宽度.该指令的重点是使用此指令的div没有设置宽度.我希望这个指令能够找出div的宽度和中心.
我遇到的问题是,当调用指令时,div的实际宽度尚不清楚.当我在我的情况下使用它时,div是800px,但是当页面加载完毕后,div为221px.
那么,我该怎么做才能等到div的实际宽度已知?
我想知道是否有一个包含所有异常类型的列表.我知道一些例外,但我不知道所有这些例外情况.有时候我抛出一个Exception,然后我想,也许.NET已经有了这个例外.
例如,现在我需要一个Exception,表示进程不存在(如文件).
所以我的问题是:有人知道找到所有例外的清单吗?我没找到.
我真的需要在bootstrapping angular之前加载一些数据.出于这个原因,我创建了一个run块/在这个run块中我调用了一个服务上的方法,该服务从服务器加载一些数据.由于这是一个异步调用,JavaScript会进一步执行,这会导致我的应用程序中出现一些未定义的对象.
我正在使用路线,但不能选择使用该resolve物业.
有人能提供一个关于如何等待承诺在run块中准备好的解决方案吗?
编辑:
感谢给定的答案,我通过手动引导角度来解决它:
$(document).ready(function () {
$.ajax('/Data/GetDropdownData', {type:'POST'}).done(function (response) {
app.run(['ListService', function (ListService) {
ListService.setData(response);
}])
angular.bootstrap(document, ["sma"]);
})
})
Run Code Online (Sandbox Code Playgroud) 我尝试清除我的listview但是clear方法不起作用:
myListView.Items.Clear();
Run Code Online (Sandbox Code Playgroud)
这不起作用.当我在这一行放置一个断点时,该行被执行,但我的listview不是空的.怎么会??
我通过将数据源设置为数据表来填充我的列表视图.
我现在的解决方案是将数据源设置为空数据表.
我只是想知道为什么清楚不做的伎俩?
我使用母版页.这里是按下按钮时内容页面的一些代码.SearchTitle方法填充ListView.
相关代码:
protected void Zoek()
{
// Clear listbox
ListView1.DataSource = new DataTable();
ListView1.DataBind();
switch (ddlSearchType.SelectedValue)
{
case "Trefwoorden":
SearchKeyword();
break;
case "Titel":
SearchTitle();
break;
case "Inhoud":
SearchContent();
break;
}
}
Run Code Online (Sandbox Code Playgroud)
填充ListView的方法
private void SearchTitle()
{
// Make panel visible
pnlResult.Visible = true;
pnlKeyword.Visible = false;
Search Search = new Search(txtSearchFor.Text);
ListView1.DataSource = Search.SearchTitle();
ListView1.DataBind();
}
Run Code Online (Sandbox Code Playgroud) 我知道ClientID用于服务器端的javascript和UniqueId,ClientID使用下划线(_),而UniqueId在asp.net 2.0中使用美元符号($).但我没有得到的是为什么使用两个不同的id.为什么不能只使用或使用下划线或在服务器端和客户端使用美元符号.有人可以解释一下吗?
我正在使用asp.net MVC框架.在我的页面上我有一个dropdwonbox,当点击一个选项时,我想转到另一个页面.但我无法找到如何/在何处将autopostback属性设置为true.这是我正在使用的代码:
ASPX:
<%= Html.DropDownList("qchap", new SelectList( (IEnumerable)ViewData["qchap"], "Id", "Title" )) %>
Run Code Online (Sandbox Code Playgroud)
控制器:
public ActionResult Index(int id)
{
Chapter c = new Chapter();
ViewData["qchap"] = c.GetAllChaptersByManual(id);
return View();
}
Run Code Online (Sandbox Code Playgroud)
使用autopostback功能我需要做什么?
抛出这个错误很多,但我找不到解决方案.我是实体框架的新手,在我的第一个方法中,我遇到了这个错误.
这就是我所拥有的.我有一个公司类和一个分支类.这两个类都有自己的存储库.公司有一个分公司,而一个分公司可以有多个公司.
在我的GUI中,我用Branch对象填充一个组合,我从BranchRepository获取:
public IList<Branch> GetAllBranches()
{
var query = _context.Branches;
IList<Branch> branches = query.ToList();
return branches;
}
Run Code Online (Sandbox Code Playgroud)
结果是分支组合框的数据源.
当我想要保存公司时,我会这样做:
company.VisitorAddress = txtVisitAddress.Text;
company.City = txtCity.Text;
company.CompanyName = txtCompany.Text;
company.PhoneNumber = txtPhoneNumber.Text;
company.ZipCode = txtZipcode.Text;
company.Branch = ((Branch)cmbBranches.SelectedItem);
company.Website = txtWebsite.Text;
Run Code Online (Sandbox Code Playgroud)
然后,我打电话给我的公司存储库以保存我的公司.以下是save方法的样子:
public bool Save(Company company)
{
_context.AddToCompanies(company); // <-- This is where the error is thrown.
_context.SaveChanges();
return true;
}
Run Code Online (Sandbox Code Playgroud)
调用save方法时,我收到错误'IEntityChangeTracker的多个实例不能引用实体对象'.
显然我做错了什么,但是什么?
当我点击GridView中的一行时,我想转到另一个页面,其中包含我从数据库中获取的ID.
在我的RowCreated事件中,我有以下行:
e.Row.Attributes.Add(
"onClick",
ClientScript.GetPostBackClientHyperlink(
this.grdSearchResults, "Select$" + e.Row.RowIndex));
Run Code Online (Sandbox Code Playgroud)
为了防止错误消息我有这个代码:
protected override void Render(HtmlTextWriter writer)
{
// .NET will refuse to accept "unknown" postbacks for security reasons.
// Because of this we have to register all possible callbacks
// This must be done in Render, hence the override
for (int i = 0; i < grdSearchResults.Rows.Count; i++)
{
Page.ClientScript.RegisterForEventValidation(
new System.Web.UI.PostBackOptions(
grdSearchResults, "Select$" + i.ToString()));
}
// Do the standard rendering stuff
base.Render(writer);
}
Run Code Online (Sandbox Code Playgroud)
如何为行添加一个唯一的ID(来自数据库),当我单击该行时,将打开另一个页面(如单击某个href),该页面可以读取该ID.
我创建了一个新的MVC6项目并构建了一个新站点.目标是获取视图的渲染结果.我找到了以下代码,但我无法让它工作,因为我找不到ControllerContext和ViewEngines.
这是我想要重写的代码:
protected string RenderPartialViewToString(string viewName, object model)
{
if (string.IsNullOrEmpty(viewName))
viewName = ControllerContext.RouteData.GetRequiredString("action");
ViewData.Model = model;
using (StringWriter sw = new StringWriter())
{
ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
viewResult.View.Render(viewContext, sw);
return sw.GetStringBuilder().ToString();
}
}
Run Code Online (Sandbox Code Playgroud) 当我执行以下操作时出现错误:
if(Session["value"] != null)
{
// code
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是这样的:
你调用的对象是空的.
为什么是这样?我总是这样检查我的会话?我正在使用MVC框架,这与它有关吗?
编辑:
代码位于Controller的构造函数中:
public class MyController : ControllerBase
{
private int mVar;
public MyController()
{
if (Session["value"] != null)
{
mVar= (int)Session["value"];
}
}
}
Run Code Online (Sandbox Code Playgroud)