小编Dan*_*ick的帖子

从数据存储中检索密钥(更新和删除实体)

我一直在阅读关于密钥的数据存储文档.

在文档中说

"一个键存储为一个对象而不是一个值."

这是结果 在此输入图像描述

以下是我的样本.ID是我试图检索以更新和删除实体的密钥

样本数据

显示结果

@page
@using TestApp.Models
@model AllSportsStoreModel

<h2>Index</h2>

<p>
    <a asp-page="SportsStore">New Item</a>
</p>
    <table class="table">
        <thead>
            <tr>
                <th>
                    @Html.DisplayName("ID")
                </th>
                <th>
                    @Html.DisplayName("Name")
                </th>
                <th>
                    @Html.DisplayName("Price")
                </th>
                <th>Edit | Delete</th>
            </tr>
        </thead>
        <tbody>
@for (var i = 0; i < Model.SportsStoreList.Count; i++) {
    <tr>
        <td>
            @Html.DisplayFor(model => model.SportsStoreList[i].Id)
        </td>
        <td>
            @Html.DisplayFor(model => model.SportsStoreList[i].PName)
        </td>
        <td>
            @Html.DisplayFor(model => model.SportsStoreList[i].Price)
        </td>
        <td>
            <a asp-page="EditStore" asp-route-Id="SportsStoreList[i].Id">Edit</a> |
            <a asp-page-handler="Delete" asp-route-Id="SportsStoreList[i].Id">Delete</a>
        </td>
    </tr>
}
        </tbody>
    </table>
    <br />
Run Code Online (Sandbox Code Playgroud)

代码背后:

using System; …
Run Code Online (Sandbox Code Playgroud)

c# google-app-engine google-cloud-datastore asp.net-core razor-pages

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

ASP日历未显示上个月和下个月的数据

我有一个ASP日历页面,从数据库中提取事件列表.我遇到的问题是当前月份显示的数据,但是当我点击下一个月和前几个月时,前几个月和下个月都没有.ASP Calendar会在单击其他月份时重新加载整个页面,还是作为查询字符串属性?

这是我目前使用的代码:

protected DataSet dsEvents;

protected void Page_Load(object sender, EventArgs e)
{
    Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
    Calendar1.NextPrevFormat = NextPrevFormat.FullMonth;
    Calendar1.TitleFormat = TitleFormat.Month;
    Calendar1.ShowGridLines = true;
    Calendar1.DayStyle.HorizontalAlign = HorizontalAlign.Left;
    Calendar1.DayStyle.VerticalAlign = VerticalAlign.Top;
    Calendar1.OtherMonthDayStyle.BackColor = System.Drawing.Color.LightGray;

    Calendar1.VisibleDate = DateTime.Today;
    FillEventDataset();
    GetFirstDayOfNextMonth();

    if (!IsPostBack)
    {
        Calendar1.VisibleDate = DateTime.Today;
        FillEventDataset();
        GetFirstDayOfNextMonth();
    }
}

protected DateTime GetFirstDayOfNextMonth()
{
    int monthNumber, yearNumber;
    if (Calendar1.VisibleDate.Month == 12)
    {
        monthNumber = 1;
        yearNumber = Calendar1.VisibleDate.Year + 1;
    }
    else
    {
        monthNumber = Calendar1.VisibleDate.Month + 1;
        yearNumber = Calendar1.VisibleDate.Year; …
Run Code Online (Sandbox Code Playgroud)

c# asp.net webforms

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

数据存储查询数组

我正在尝试运行数据存储区查询以获取名称和价格列表.但是,我不断收到此错误消息:

无法隐式将类型' Google.Cloud.Datastore.V1.DatastoreQueryResults' 转换为' System.Collections.Generic.List<TestApp.Models.AllSportsStore>'

这是我正在使用的代码:

AllSportsStore.cs

public DatastoreDb _db;

[BindProperty]
public List<AllSportsStore> SportsStoreList { get; set; }


public void OnGet()
{
    Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "xxxxx.json"));
    _db = DatastoreDb.Create("projectid");
    Query query = new Query("Sports_db");
    IEnumerable<Entity> stores = _db.RunQuery(query).Entities;
    SportsStoreList = stores.Select(_ => new AllSportsStore
    {
        Name = _["Name"].ToString(),
        Price = _["Price"].ToString(),
    }).ToList();
}
Run Code Online (Sandbox Code Playgroud)

AllSportsStore.cshtml页面

@for (var i = 0; i < Model.SportsStoreList.Count; i++)
{
    <tr>
        <td>
            @Html.DisplayFor(model => model.SportsStoreList[i].Name)
        </td>
        <td>
            @Html.DisplayFor(model => model.SportsStoreList[i].Price)
        </td>
    </tr>
}
Run Code Online (Sandbox Code Playgroud)

这是数据存储区的映像

数据存储区图像

根据评论更新了代码结果 在此输入图像描述

c# asp.net-mvc razor google-cloud-datastore

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

背后的新 System.Drawing.Font 代码

我正在尝试使用名为 Black Rose 的字体在 c# 中创建图像。图像被创建,但不是我想要的字体。这是我用来创建图像的代码:

    protected void Page_Load(object sender, EventArgs e)
    {
        string MoneyImg = "1000";
        Bitmap bitmap = new Bitmap(MoneyImg.Length * 40, 150);

        using (Graphics graphics = Graphics.FromImage(bitmap))
        {
            Font oFont = new System.Drawing.Font("BLACKR", 20);
            PointF point = new PointF(2f, 2f);
            SolidBrush black = new SolidBrush(Color.Black);
            SolidBrush white = new SolidBrush(Color.White);
            graphics.FillRectangle(white, 0, 0, bitmap.Width, bitmap.Height);
            graphics.DrawString("$" + MoneyImg , oFont, black, point);
        }
    }
Run Code Online (Sandbox Code Playgroud)

我试着改变这条线

Font oFont = new System.Drawing.Font("BLACKR", 20);
Run Code Online (Sandbox Code Playgroud)

Font oFont = new System.Drawing.Font("BLACKR.TTF", …
Run Code Online (Sandbox Code Playgroud)

css c# fonts

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

JQuery Dymanic Button

我有一个输入框.我输入搜索词并返回值.我要做的是单击动态按钮并附加值.但是,当我点击按钮时,它会重新加载页面而不是显示警告框.这只发生在动态按钮而不是searchButton上

$(document).ready(function () {
        $('.cta-button').click(function () {
            event.preventDefault();
            alert("You clicked the button");
        });

        $('#searchButton').click(function () {
            event.preventDefault();
            var varSearch = $('#searchDB').val();
            if (!varSearch) {
                $('#result').html("Please enter a search term");
                return;
            }
            $.ajax({
                contentType: "application/json; charset=utf-8",
                data: 'ID=' + varSearch,
                url: "getTest.ashx",
                dataType: "json",
                success: function (data) {
                    var result = '';
                    $.each(data, function (index, value) {
                        result += '' +
                            '<div class="main-area bg-white">' +
                            '<div class="row">' +
                                '<div class="medium-6 columns">' +
                                    '<button type="submit" id="OfferID_' + index + '" class="cta-button cta-button-icon">Add …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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

如何使用没有控制器的 Razor 页面填充下拉列表

我被困在这一部分上。当我进行搜索时,出现的只是控制器、视图包和 MVC 中其他示例的示例。

我正在尝试从数据库填充下拉列表。到目前为止,这是我的代码

类别.cs

public class Category
{
    [Key]
    public int CategoryID { get; set}
    public string CategoryName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

编辑器.cshtml.cs

public class Editor : PageModel
{
    private readonly DatabaseContext _context;

    public Editor(DatabaseContext databasecontext)
    {
       _context = databasecontext;
    }

    public void OnGet()
    {
        List<Category> categoryList = new List<Category>();
        categoryList = (from Category in _context.Category select Category).ToList();
        categoryList.Insert(0, new Category { CategoryID = 0, CategoryName = "Select" });
    }
}
Run Code Online (Sandbox Code Playgroud)

将下拉列表附加到 Razor 视图页面的下一步是什么?

razor asp.net-core asp.net-core-2.0

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