我有2个实体,我需要找到一种方法来避免使用两个foreach函数:
public class IzigoKeyword
{
public int Id { get; set; }
public string Name { get; set; }
// Navigation properties
public Address Address { get; set; }
public virtual ICollection<Keyword> Keywords { get; set; }
}
public class Keyword
{
public int Id { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
直到现在的功能:
public IList<int> GetKeywordIdsFromIzigoKeywordIds(IList<int> izigoKeywordIds)
{
IList<int> keywordIds = new List<int>();
foreach (var izigoKeywordId in izigoKeywordIds)
{
var keywords = _izigoKeywordRepository.Query.Where(ik => ik.Id == izigoKeywordId).Select(ik => ik.Keywords);
foreach (var keyword …Run Code Online (Sandbox Code Playgroud) 有没有办法让这个工作:
@foreach (var item in Model.CategoryListByKeywordsDetails)
{
<li>
@Html.ActionLink("ver >", MVC.Ad.ListByCategory(item.Id, (string)ViewBag.keywords))
{
<em>@Html.DisplayFor(modelItem => item.SearchCount)</em> @Html.DisplayFor(modelItem => item.Name) <span class="float-right">ver ></span>
}
</li>
}
Run Code Online (Sandbox Code Playgroud)
我想要结果(我放了空格来显示 HTML 代码):
<a href="/Ad/ListByCategory?categoryId=1&keywords=alfa">
<em>6</em>Carros
<span class="float-right">ver ></span>
</a>
Run Code Online (Sandbox Code Playgroud) 我需要通过Messages Answers对邮件进行分组,如下所示:
消息回答id = 4 /父消息id = 1
消息ID = 5
消息模型:
public class Message
{
// Primary properties
public int Id { get; set; }
public string NameFrom { get; set; }
public string EmailFrom { get; set; }
public string TelephoneFrom { get; set; } …Run Code Online (Sandbox Code Playgroud) 我有Viewmodel:
public class PartnerSearchResultVM
{
public int Id { get; set; }
public string Name { get; set; }
public string Latitude { get; set; }
public string Longitude { get; set; }
public double Distance { get; set; }
public string Classification { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我从数据库得到距离,如下所示:2354,58764478263 m
我想要2.35公里
如何更改Viewmodel以在那里进行转换(如果它是最好的位置)
我的莫里斯图表未显示最后一个 xkey 值:
\n\n\n\n有什么想法吗?
\n\n我的数据是:
\n\n[{"Date":"2016-07-17","Average":0.0},{"Date":"2016-07-16","Average":0.0},{"Date":"2016-07-15","Average":4.125},{"Date":"2016-07-14","Average":0.0},{"Date":"2016-07-13","Average":0.0},{"Date":"2016-07-12","Average":0.0},{"Date":"2016-07-11","Average":0.0}]\nRun Code Online (Sandbox Code Playgroud)\n\n风景:
\n\n<script>\n var surveyLastDaysChartData = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.SurveyLastDaysChartData));\n</script>\n\n <div class="col-lg-6">\n <div class="card-box">\n <h4 class="header-title m-t-0">M\xc3\xa9dia dos \xc3\xbaltimos 7 dias</h4>\n <div id="dsb-survey-last-days-chart" style="height: 217px;"></div>\n </div>\n </div><!-- end col -->\nRun Code Online (Sandbox Code Playgroud)\n\n构建它的脚本:
\n\nvar _surveyLastDaysChartId = "dsb-survey-last-days-chart";\n\nMorris.Line({\n // ID of the element in which to draw the chart.\n element: _surveyLastDaysChartId,\n // Chart data records -- each entry in this array corresponds to a point on the chart.\n data: surveyLastDaysChartData,\n // The name …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个可以根据屏幕大小调整大小的简单流体图像。
但是当浏览器的宽度变小时,我很难把图像变小。
HTML:
<main>
<section class="slider-ctn">
<figure class="logo"></figure>
</section>
</main>
Run Code Online (Sandbox Code Playgroud)
CSS:
.slider-ctn figure.logo {
margin: auto;
background-image: url('../Images/logo.200x100.png');
width: 200px;
height: 100px;
}
Run Code Online (Sandbox Code Playgroud) 我有一个计数器来计算视图的显示次数:
public class News
{
[Key]
public int Id { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DatePostedOn { get; set; }
public DateTime DateModified { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Meta { get; set; }
public string UrlSlug { get; set; }
public bool Popular { get; set; }
public int Position { get; set; }
public int Views { …Run Code Online (Sandbox Code Playgroud) 我有搜索具有特定类的每个元素的函数:
$("#stepSurveyCtnId .questionCtnClass").each(function () {}
Run Code Online (Sandbox Code Playgroud)
在每个步骤中,我检查一个问题是否是客户类型:
var type = $(this).children().data("question-type");
var isCustomerQuestion = false;
switch (type) {
case "Name":
case "Email":
isCustomerQuestion = true;
break;
}
Run Code Online (Sandbox Code Playgroud)
如果是客户类型,我从数据库中获取客户表的下一个ID:
if(isCustomerQuestion) {
if (customerId == -1) {
$.ajax({
method: "POST",
url: urlCustomerCreate,
success: function (ajaxData) {
customerId = ajaxData.NumericValue;
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
问题是在.each()函数的第二次迭代中,customerId仍然是= -1,例如它应该是1305.
似乎执行不会在$ .ajax调用中停止,或者迭代在同一时间执行,第二次迭代不会从第一次迭代中接收customerId.
如何获取具有一个单词的表的所有行,以及具有多个单词的表的所有行:
例如,请记录以下内容:
CARROCARIA PINTURA
VEICULOS ALUGUER
VEICULOS ELETRICOS
SERVICOS RAPIDOS
VEICULOS COMERCIAIS
ELETRICIDADE
VIDROS
Run Code Online (Sandbox Code Playgroud)
我得到查询1:
ELETRICIDADE
VIDROS
Run Code Online (Sandbox Code Playgroud)
我得到了查询2:
CARROCARIA PINTURA
VEICULOS ALUGUER
VEICULOS ELETRICOS
SERVICOS RAPIDOS
VEICULOS COMERCIAIS
Run Code Online (Sandbox Code Playgroud)
谢谢.
有时,Google地图无法正确加载,也不允许插入标记:

这是我创建地图的代码:
var companyCreateMap;
var companyCreateMapInitialZoom = 7;
function companyLoadInitialMap()
{
companyCreateGeocoder = new google.maps.Geocoder();
var companyCreateInitialLocation = new google.maps.LatLng(companyCreateMapInitialCenterLat, companyCreateMapInitialCenterLng);
var companyCreateMapOptions = {
center: companyCreateInitialLocation,
zoom: companyCreateMapInitialZoom,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
companyCreateMap = new google.maps.Map(document.getElementById(companyCreateMapCanvas), companyCreateMapOptions);
google.maps.event.addListener(companyCreateMap, 'click', updateMarkerCoordenatesOnClick);
companyCreateGetUserLocation();
}
function companyCreateGetUserLocation()
{
if (navigator.geolocation)
{
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function (companyCreatePosition)
{
var companyCreateCenterLocation = new google.maps.LatLng(companyCreatePosition.coords.latitude, companyCreatePosition.coords.longitude);
companyCreateMap.setCenter(companyCreateCenterLocation);
companyCreateMap.setZoom(17);
companyCreateMarker = new google.maps.Marker({ position: companyCreateCenterLocation, map: companyCreateMap, animation: google.maps.Animation.DROP });
},
function (error)
{
// User did …Run Code Online (Sandbox Code Playgroud) 我需要使用剃刀设置DropDownList的setectedValue,但是由于它是在同一页面中多次使用的列表,因此无法在Controller中设置所选值,那么如何在View中进行设置?
实际控制器列表代码:
ViewBag.CargaTipos = new SelectList(db.CargaTipos, "Id", "Nome").OrderBy(c => c.Text);
Run Code Online (Sandbox Code Playgroud)
实际视图:
@Html.DropDownListFor(modelItem => item.CargaTipo.Id, (IEnumerable<SelectListItem>)ViewBag.CargaTipos)
Run Code Online (Sandbox Code Playgroud)
楷模:
[Table("Cargas")]
public class Carga
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
[ForeignKey("CargaTipo")]
public int CargaTipo_Id { get; set; }
[Display(Name = "Tipo de Carga")]
public virtual CargaTipo CargaTipo { get; set; }
}
[Table("CargaTipos")]
public partial class CargaTipo
{
public CargaTipo()
{
this.Cargas = new HashSet<Carga>();
}
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string Nome { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 MVC lib ClosedXML 将文本居中,但它仅在单元格设置了背景颜色并且我想在没有它的情况下设置对齐时才有效:
var workbook = new XLWorkbook("c:\\temp\\file.xlsx");
var worksheet = workbook.Worksheet("Sheet");
worksheet .Cell(1, 1).Style.Fill.BackgroundColor = XLColor.White; // without this line it doe not work
worksheet.Cell(1, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
Run Code Online (Sandbox Code Playgroud) 我想对 Average Linq 函数的结果进行四舍五入,可以吗?
public IEnumerable<GetLocationsAverageDTO> GetLocationsAverageByCompanyId(int id)
{
try
{
var baseQuery = _dbContext.Answers.AsNoTracking()
.Where(p => p.Location.Company.Id == id
&& p.Question.Type != QuestionType.Text)
.GroupBy(g => new { Location = g.Location.Name })
.Select(x =>
new GetLocationsAverageDTO
{
LocationName = x.Key.Location,
Average = x.Average(f => f.Numeric)
})
.OrderBy(x => x.LocationName);
var dto = baseQuery.ToList();
return dto;
}
catch (Exception error)
{
_logger.Error("[Error in SurveyService.GetLocationsAverageByCompanyId - id: " + id + " - Error: " + error + "]");
return null;
} …Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×8
c# ×6
javascript ×3
linq ×3
jquery ×2
razor ×2
asp.net ×1
css ×1
excel ×1
fluid-layout ×1
html ×1
morris.js ×1
sql ×1
sql-server ×1
t4mvc ×1
viewmodel ×1