小编Pat*_*ick的帖子

获取没有2个foreach函数的相关实体ID

我有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)

c# linq asp.net-mvc

2
推荐指数
1
解决办法
88
查看次数

ActionLink 使用 T4MVC 和一个 HTML 代码块

有没有办法让这个工作:

@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 &gt;</span>
</a>
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc t4mvc razor

1
推荐指数
1
解决办法
840
查看次数

消息回答由父原始消息分组

我需要通过Messages Answers对邮件进行分组,如下所示:

  • 消息ID = 1
  • 消息答案id = 2 /父消息id = 1
  • 消息答案id = 3 /父消息id = 1
  • 消息回答id = 4 /父消息id = 1

  • 消息ID = 5

  • 消息答案id = 6 /父消息id = 5
  • 消息答案id = 7 /父消息id = 5
  • 消息回答id = 8 /父消息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)

c# linq asp.net-mvc

1
推荐指数
1
解决办法
193
查看次数

将米转换为千米并在Viewmodel中格式化值

我有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以在那里进行转换(如果它是最好的位置)

c# asp.net-mvc viewmodel

1
推荐指数
1
解决办法
5100
查看次数

Morris 图表未显示 MVC 的最后一个 xkey 值

我的莫里斯图表未显示最后一个 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}]\n
Run 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 -->\n
Run Code Online (Sandbox Code Playgroud)\n\n

构建它的脚本:

\n\n
var _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)

javascript asp.net-mvc morris.js

1
推荐指数
1
解决办法
2131
查看次数

使用 CSS 创建流体背景图像

我正在尝试构建一个可以根据屏幕大小调整大小的简单流体图像。

但是当浏览器的宽度变小时,我很难把图像变小。

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)

html css fluid-layout responsive-design

1
推荐指数
1
解决办法
1万
查看次数

MVC View News计数器和Google Analytics之间存在巨大差异

我有一个计数器来计算视图的显示次数:

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)

asp.net-mvc google-analytics

1
推荐指数
1
解决办法
107
查看次数

在.each函数中等待$ .ajax结果

我有搜索具有特定类的每个元素的函数:

$("#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.

javascript jquery

1
推荐指数
1
解决办法
223
查看次数

使用SQL Server获取包含多个单词的行

如何获取具有一个单词的表的所有行,以及具有多个单词的表的所有行:

例如,请记录以下内容:

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)

谢谢.

sql sql-server

0
推荐指数
1
解决办法
64
查看次数

Google地图无法每次都正确加载

有时,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)

javascript jquery google-maps-api-3

0
推荐指数
1
解决办法
774
查看次数

在视图中设置下拉列表选择的值

我需要使用剃刀设置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)

c# asp.net asp.net-mvc razor

0
推荐指数
1
解决办法
4956
查看次数

无法使用 C# lib ClosedXML 将文本居中

我正在尝试使用 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)

c# asp.net-mvc excel

0
推荐指数
1
解决办法
6540
查看次数

舍入平均 Linq 函数 C#

我想对 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)

c# linq

-2
推荐指数
2
解决办法
1万
查看次数