我正在尝试使用blazor.Net,这是一个实验框架。
我已经在这个Framework及其出色的工具中开发了一个小项目。
但是在11月14日Blazor语言服务最近更新之后,我在模板选择中看到了owo选项。
首先是Blazor(托管ASP.NET Core)
其次是Blazor(ASP.NET Core中的服务器端)
没有关于它们之间差异的信息,
谁能告诉我这两个模板之间的区别是什么,何时应选择哪个?
我曾经使用下面的代码将数据导出到asp.net mvc中的excel
Response.AppendHeader("content-disposition", "attachment;filename=ExportedHtml.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
this.EnableViewState = false;
Response.Write(ExportDiv.InnerHtml);
Response.End();
Run Code Online (Sandbox Code Playgroud)
当此代码运行时,它会创建一个文件并要求保存位置
我尝试使用NPOI并很好地创建Excel文件,但无法在客户端位置保存文件.
有没有办法让上面的代码适用于asp.net core 2.0或者我可以在客户端机器上以excel格式保存数据的任何其他方式?
我正在尝试从数据库中检索一行,更改其中的某些列值并将其添加为新行(实体框架核心),
但它给了我错误
当 IDENTITY_INSERT 设置为 OFF 时,无法为表“Audit_Schedules”中的标识列插入显式值。
该表有一个主键“ScheduleId”
下面是我的代码
AuditSchedules _schedules = new AuditSchedules();
using (var ctx = new QuestionnaireEntities(_configuration))
{
_schedules = ctx.AuditSchedules.Where(x => x.ScheduleId == model.ScheduleID).SingleOrDefault();
_schedules.StaffId = model.TransferedAuditorCode;
_schedules.StaffName = model.TransferedAuditorName;
_schedules.FromDate = _schedules.ToDate = Convert.ToDateTime(model.TransferedScheduleDate);
ctx.AuditSchedules.Add(_schedules);
ctx.SaveChanges();
_subschedules = ctx.AuditSubSchedule.Where(x => x.SubScheduleId == model.SubScheduleID).SingleOrDefault();
_subschedules.IsHoliDay = "Y";
_subschedules.HolidayType = model.HolidayType;
_subschedules.TransferedScheduleId = _schedules.ScheduleId.ToString();
ctx.AuditSubSchedule.Update(_subschedules);
ctx.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)
错误进来
ctx.AuditSchedules.Add(_schedules);
Run Code Online (Sandbox Code Playgroud)
首先我认为它与 Schedule_ID 的值冲突并且无法添加重复的 Primary Key ,但 Schedule_ID 是自动生成的字段,因此不应发生此问题
我也尝试将其设置为不同的值
_schedules.ScheduleId = 0;
Run Code Online (Sandbox Code Playgroud)
但它不插入。我如何复制一行中几乎没有变化的行(想添加一个新行但修改了值)
我用.NET Core开发了很少的angular应用程序,但是每次Angular应用程序都是分开的,而.NET Core API是分开的。
现在我正在使用内置的Angular模板开发Angular应用程序,该模板在同一项目中包含API。
我曾经用完整的URL调用api(通过将基本URL定义为http:// portNumber:在服务中),但是在此内置模板中,这就是我得到的
export class FetchDataComponent {
public forecasts: WeatherForecast[];
constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
http.get<WeatherForecast[]>(baseUrl + 'api/SampleData/WeatherForecasts').subscribe(result => {
this.forecasts = result;
}, error => console.error(error));
}
}
Run Code Online (Sandbox Code Playgroud)
它的内置组件带有角度模板
这里写成
http.get<WeatherForecast[]>(baseUrl + 'api/SampleData/WeatherForecasts')
Run Code Online (Sandbox Code Playgroud)
经过一番搜索后,我在main.ts中找到了一个方法getBaseUrl(),其常量提供者 为
export function getBaseUrl() {
return document.getElementsByTagName('base')[0].href;
}
const providers = [
{ provide: 'BASE_URL', useFactory: getBaseUrl, deps: [] }
];
Run Code Online (Sandbox Code Playgroud)
现在有人可以向我解释如何从此处从Base Url获得 @Inject('BASE_URL')组件而不在服务中共享它吗?
在angularJS中,我曾经在@ url.action的帮助下实现了相同的效果
$http({
url: "@Url.Action("Action", "Controller")",
params: …Run Code Online (Sandbox Code Playgroud) 在 asp.net core 2.1 应用程序中使用旋转将视图转换为 pdf 时会出现错误
值不能为空。参数名称:path1
下面是我的代码
var rpt = new ViewAsPdf();
//rptLandscape.Model = Model;
rpt.PageOrientation = Rotativa.AspNetCore.Options.Orientation.Landscape;
rpt.PageSize = Rotativa.AspNetCore.Options.Size.A4;
rpt.ViewName = "Test";
byte[] arr = await rpt.BuildFile(actionContextAccessor.ActionContext);
System.IO.File.WriteAllBytes(Path.Combine(env.WebRootPath, "PDFStorage", "File.pdf"), arr);
Run Code Online (Sandbox Code Playgroud)
虽然它成功地将网页返回为 pdf,但我想将它存储在一个文件夹中。此错误的可能原因是什么?,我已经检查了所有,它甚至不包含名称 name1 的属性
更新 1:错误不在 Path.Combine() 中,错误在它之前。
byte[] arr = await rpt.BuildFile(actionContextAccessor.ActionContext);
Run Code Online (Sandbox Code Playgroud) 以下是我的Typescript代码,可从API下载文件
DownloadLM() {
var ID= sessionStorage.getItem("UserID");
return this.http.get(this.baseurl + 'api/DownloadFiles/DownloadLM/' + ID,
{
headers: {
'Content-Type': 'application/json'
},
responseType: 'arraybuffer'
}
)
.subscribe(respData => {
this.downLoad(respData, this.type);
}, error => {
});
}
downLoad(data: any, type: string) {
var blob = new Blob([data], { type: type.toString() });
var url = window.URL.createObjectURL(blob);
var pwa = window.open(url);
if (!pwa || pwa.closed || typeof pwa.closed == 'undefined') {
alert('Please disable your Pop-up blocker and try again.');
}
}
Run Code Online (Sandbox Code Playgroud)
下载Excel文件很好,但是它给我不需要的文件一个随机的名字,我要在下载时设置自己选择的文件名,
在哪里可以设置文件名?Blob的任何属性?
在我的 Angular 应用程序中,我在输入字段中显示从 API 到组件的数据。
所有字段都已填充,但日期类型的输入元素未填充
下面是 html 标记
<input [(ngModel)]="CustomerVM.customer.CustomerDob" type="date" name="MemberDateOfBirth" class="form-control"
(blur)="Calculate_Age(CustomerVM.customer.CustomerDob)">
Run Code Online (Sandbox Code Playgroud)
在控制台中它说
指定值“2018-09-21T00:00:00”不符合所需的格式“yyyy-MM-dd”。
我做了一个通用函数来将服务中的日期格式化为
FormatDate(iDate: Date) {
var inputDate:Date= new Date(iDate);
var formattedDate = new Date(inputDate.getUTCDate(), (inputDate.getUTCMonth() + 1), inputDate.getUTCFullYear());
return formattedDate;
Run Code Online (Sandbox Code Playgroud)
}
和
this.CustomerVM.customer.CustomerDob = this.Helper.FormatDate(this.CustomerVM.customer.CustomerDob);
Run Code Online (Sandbox Code Playgroud)
但它不显示日期字段中的值
在插值块内,我们可以使用管道格式化值
{{DOB | date:'mediumDate'}}
Run Code Online (Sandbox Code Playgroud)
我们也可以用 ngModel 来做这个吗?因为我不想要一种格式化它的方法。
我怎样才能做到这一点?
我在.Net Core中有一个API,我在angular 5 app中使用它
以下是我的API
[Route("api/[controller]")]
public class CommonController : Controller
{
private readonly IConfiguration configuration;
private readonly CommonUtility util;
public CommonController(IConfiguration _configuration)
{
configuration = _configuration;
util = new CommonUtility(_configuration);
}
[HttpGet("[action]/{StaffCode}")]
public string GetUserName(string StaffCode)
{
return util.GetName(StaffCode);
}
}
Run Code Online (Sandbox Code Playgroud)
它确实返回一个字符串值,在swagger UI中检查
现在是Angular Code
GetUserName() {
this.http.get<string>(this.baseUrl + 'api/Common/GetUserName/' + this.StaffCode).subscribe(result => {
sessionStorage.setItem("UserName", result);
alert(sessionStorage.getItem("UserName"));
}, error => console.log(error));
Run Code Online (Sandbox Code Playgroud)
}
在调用API之后,我在控制台中得到了输出
当我尝试将结果存储在会话中而不是它给出语法错误JSON.parse()中位置0的JSON中的意外的标记S
如何在角度使用API的输出?
我正在尝试从Angular 5将base64字符串发布到我的api
首先,我必须将其从图像转换为base64,在Internet和MDN上进行检查之后,我开发了一种方法
OnIDChange(event) {
var file = event.target.files[0];
var reader = new FileReader();
reader.onloadend = this.handleReaderLoaded.bind(this, "Id");
reader.readAsBinaryString(file);
}
Run Code Online (Sandbox Code Playgroud)
和
handleReaderLoaded(readerEvt:any, indicator: string) {
var binaryString = readerEvt.target.result;
if (indicator == "Id") {
this.Model.IDPhoto = btoa(binaryString);
}
}
Run Code Online (Sandbox Code Playgroud)
我必须将此base64存储在模型属性中才能在api中发布
但是在控制台上,它给出错误“无法读取未定义的属性'结果'”
var binaryString = readerEvt.target.result;
我如何将图像转换为base64,如果还有其他更合适的方法(任何npm包或其他东西,也请让我知道)
提前致谢 。
来自MDN MDN链接的参考
借助互联网上的一些示例,我可以开发ASP.NET Core Hosted Blazor应用程序.
但是,虽然呼吁api如下
private async Task Refresh()
{
li.Clear();
li = await Http.GetJsonAsync<SampleModel[]>("/api/Sample/GetList");
StateHasChanged();
}
private async Task Save()
{
await Http.SendJsonAsync(HttpMethod.Post, "api/Sample/Add", obj);
await Refresh();
}
Run Code Online (Sandbox Code Playgroud)
在下面的行中:
await Http.SendJsonAsync(HttpMethod.Post, "api/Sample/Add", obj);
Run Code Online (Sandbox Code Playgroud)
如何查看此HTTP呼叫的状态代码?
如果API调用中出现任何问题而不是我想显示消息.
但当我这样做时:
HttpResponseMessage resp = await Http.SendJsonAsync(HttpMethod.Post, "api/Sample/Add", obj);
Run Code Online (Sandbox Code Playgroud)
然后它说:
无法将
HttpResponse消息转换为消息
我使用以下方法:
GetJsonAsync() // For HttpGet
SendJsonAsync() // For HttpPost And Put
DeleteAsync() // For HttpDelete
Run Code Online (Sandbox Code Playgroud)
如何在此验证状态代码?
c# asp.net-core-webapi blazor asp.net-core-2.1 blazor-server-side
我将输入元素与 angular 5 中的模型属性绑定
<input [(ngModel)]="MB.YearOfOperation | date: 'dd-MMM-yyyy' " type="text" class="form-control">
Run Code Online (Sandbox Code Playgroud)
使用日期管道格式化其值但它给出了错误
在第 33 列的操作表达式中不能有管道
所以我尝试了以下方法(ngModelChange)
<input [(ngModel)]="MB.YearOfOperation | date: 'dd-MMM-yyyy' " (ngModelChange)="MB.YearOfOperation =$event" type="text" class="form-control">
Run Code Online (Sandbox Code Playgroud)
但它仍然给出相同的错误,我如何使用带有 [(ngModel)] 的管道?
我正在Angular 5中开发一个应用程序
在我的ts文件中,我将字符串数组设置为
breadCumbSetter.bCumb = [
{name:'Operation',route:'/operation'},
];
Run Code Online (Sandbox Code Playgroud)
在我看来,我正在使用它如下
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a [routerLink]="['/dashboard']">
<i class="fa fa-home"></i>
</a>
</li>
<li class="breadcrumb-item" *ngFor="let item of breadCumbSetter.bCumb">
<a [routerLink]="['"+{{item.route}}+"']">{{item.name}}</a>
</li>
</ol>
Run Code Online (Sandbox Code Playgroud)
我正面临着问题
<a [routerLink]="['"+{{item.route}}+"']">{{item.name}}</a>
Run Code Online (Sandbox Code Playgroud)
我无法在routerLink中设置路由值,我也尝试了很多在网络上找到的建议,
[routerLink]="item.route"
routerLink=[item.route]
Run Code Online (Sandbox Code Playgroud)
但没有任何作用,
如何通过插值设置routerLink值,或者在*ngFor循环中有没有其他方法可以做到这一点?