我一直在阅读关于密钥的数据存储文档.
在文档中说
"一个键存储为一个对象而不是一个值."
以下是我的样本.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
我有一个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) 我正在尝试运行数据存储区查询以获取名称和价格列表.但是,我不断收到此错误消息:
无法隐式将类型'
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)
这是数据存储区的映像
我正在尝试使用名为 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) 我有一个输入框.我输入搜索词并返回值.我要做的是单击动态按钮并附加值.但是,当我点击按钮时,它会重新加载页面而不是显示警告框.这只发生在动态按钮而不是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) 我被困在这一部分上。当我进行搜索时,出现的只是控制器、视图包和 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 视图页面的下一步是什么?
c# ×4
asp.net-core ×2
razor ×2
asp.net ×1
asp.net-mvc ×1
css ×1
fonts ×1
javascript ×1
jquery ×1
razor-pages ×1
webforms ×1