我的页面上有一个jquery UI对话框.它只包含一个asp FileUpload控件:
<asp:FileUpload runat="server" ID="fuAttachment" />
Run Code Online (Sandbox Code Playgroud)
对话框有1个按钮"OK".那些按钮只是关闭对话框
$("#attachment-dialog").dialog({
height: 300,
width: 400,
modal: true,
resizable: false,
autoOpen: false,
buttons: {
"OK": function () {
$(this).dialog("close");
}
}
});
Run Code Online (Sandbox Code Playgroud)
按下我页面上的保存按钮.这是一个asp.net按钮,调用SaveAttachement方法.
问题是fuAttachment.HasFile(fileupload控件)一直返回false.如果我将fileupload控件移到jQuery UI对话框之外.HasFile = true.
但控件应该在对话框内.特定页面内没有更新面板.
如何从.cs文件访问母版页属性?我尝试了下面的代码,但我无法访问它.请让我知道.
public int TypeID
{
get
{
return Convert.ToInt32(this.ViewState["TypeID"]);
}
set
{
this.ViewState.Remove("TypeID");
this.ViewState.Add("TypeID", value);
}
}
Run Code Online (Sandbox Code Playgroud)
var pageHandler = HttpContext.Current.CurrentHandler;
if (pageHandler is System.Web.UI.Page)
{
typeId = Convert.ToInt32((System.Web.UI.Page)pageHandler).Master.TypeID;
}
Run Code Online (Sandbox Code Playgroud) 我有一个将电子邮件发送到列表的例程,如下所示,我已经对其进行了测试。给我的第一封电子邮件很好,但第二封电子邮件的字节数少于实际文件使其损坏无法打开的字节数。我怎样才能使每个电子邮件附件都正确发送而不发送任何 0 字节附件?我通过 ASP.NET C# 网络表单将附件直接发送给收件人,但大多数 PDF 附件都被错误地解码为错误消息。这是页面的主要电子邮件代码:
if (emailIsValid(EmailToSend))
{
string TheSubject = SubjectTxt.Text;
string TheBody = "Dear " + FirstName + ",<br/><br/>" + MessageTxt.Text;
TheBody = TheBody + " EMail Body "
string BodyTxt = TheBody.Replace(Environment.NewLine, "<br />");
MailMessage mailObj = new MailMessage(
"noreply@company.com", EmailToSend, TheSubject, BodyTxt);
SmtpClient SMTPServer = new SmtpClient("unknown.company.com");
string RPT = FromTxt.Text;
mailObj.ReplyToList.Add(RPT);
mailObj.BodyEncoding = System.Text.Encoding.UTF8;
mailObj.IsBodyHtml = true;
string filePath = txtAttachment.PostedFile.FileName;
string filename = Path.GetFileName(filePath);
string ext = Path.GetExtension(filename);
string contenttype = …Run Code Online (Sandbox Code Playgroud) 我想做的是显示网络根文件夹中的图像,这就是我尝试执行此操作的方式:
下面的课程只是实验性的,只是我尝试的例子。目前正在读取的文件夹中只有一张图像。rootPath 也取自:_hostingEnvironment.WebRootPath
public class GetRandomImageForGalleryView : IGetRandomImageFromFolder
{
private string rootPath;
public GetRandomImageForGalleryView(string rootPath)
{
this.rootPath = rootPath;
}
public string[] getImage()
{
return ReadPhotosFromDirectory();
}
private string[] ReadPhotosFromDirectory()
{
string[] fileLocations = Directory.GetFiles(rootPath+"\\lib\\Images\\Nature");
return fileLocations;
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我试图显示它的方式:
@model IGetRandomImageFromFolder
@{
ViewBag.Title = "Gallery";
}
<div class="container">
<div class="row">
@{
foreach (string item in Model.getImage())
{
<img src="@item" alt="Image" />
}
}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
但是没有输出,即使我将其更改为<img src="@Url.Content(item)" alt="Image" />仍然没有发生。
如果我只是输出@item它会显示图像的路径。也已 app.UseStaticFiles();添加。
所以我的问题是我做错了什么,我错过了什么吗?以及如何正确地做到这一点?
我试图通过Visual Studio创建一个新的ASP.NET Core Web应用程序,当新项目对话框打开时,我注意到它提供了两个ASP.NET Core模板,一个使用.NET核心,另一个使用.NET Framework.为什么两个模板?ASP.NET核心应用程序如何使用常规.NET框架?
嗨,我正在尝试捕获用户在 C# 日历控件中选择的两个日期,我希望日期范围显示在标签中。我已经制定了以下代码,但它生成了一个 Minus 值;不是实际的日期范围。
DateTime from = CalFrom.SelectedDate;
DateTime to = CalTo.SelectedDate;
double days = (CalTo.SelectedDate - CalFrom.SelectedDate).TotalDays;
TimeSpan t = to - from;
double noOfDays = t.TotalDays;
TimeSpan ts = to - from;
double differnceindays = ts.TotalDays;
lblNoofDays.Text = differnceindays.ToString();
Run Code Online (Sandbox Code Playgroud) 嗨,我在学习 c# 时遇到了麻烦,因为在 Java 中我习惯于在 Java 中执行此操作
public class Product
{
private double price;
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
public class Item
{
private int quantity;
private Product product;
public double totalAmount()
{
return product.getPrice() * quantity;
}
}
Run Code Online (Sandbox Code Playgroud)
totalAmount() 方法是我如何使用 Java 访问另一个类中对象的值的一个示例。我怎样才能在 c# 中实现同样的事情,这是我的代码
public class Product
{
private double price;
public double Price { get => price; set => price = value; }
}
public class …Run Code Online (Sandbox Code Playgroud) 在提交表单时,我在其中一个字段中插入了易受攻击的字符,例如=cmd|'/C calc'!A0. 因此,从安全角度来说,它在导出功能中被称为CSV 注入
我已经为上述错误编写了这样的代码。但它不起作用
[WebMethod]
public static string SaveRecord(RRSOCSaving RRSOCSaving, string Indication)
{
string strReturnId = "";
string strAppURL = ConfigurationManager.AppSettings["AppUrl"].ToString();
string strmail_Content = "";
CommonDB commonObj = new CommonDB();
try
{
// Cross site scripting issue code tag..!!
if (commonObj.HackerTextExistOrNot(RRSOCSaving.STORE_CODE)
|| commonObj.HackerTextExistOrNot(RRSOCSaving.CITY)
|| commonObj.HackerTextExistOrNot(RRSOCSaving.STORE_SITENAME)
|| commonObj.HackerTextExistOrNot(RRSOCSaving.STORE_SITENAME_LANDL_1)
|| commonObj.HackerTextExistOrNot(RRSOCSaving.STORE_SITENAME_LANDL_2)
|| commonObj.HackerTextExistOrNot(RRSOCSaving.STORE_ASST_MANAGER_NAME)
|| commonObj.HackerTextExistOrNot(RRSOCSaving.STORE_ASST_MANAGER_MOBNO)
|| commonObj.HackerTextExistOrNot(RRSOCSaving.STORE_MANAGER_NAME)
|| commonObj.HackerTextExistOrNot(RRSOCSaving.MANAGER_MOBNO)
|| commonObj.HackerTextExistOrNot(RRSOCSaving.EMP_NEAREST_STORE)
|| commonObj.HackerTextExistOrNot(RRSOCSaving.EMP_NEAREST_STORE_MOBNO)
|| commonObj.HackerTextExistOrNot(RRSOCSaving.SUPERVISOR_MOBNO)
|| commonObj.HackerTextExistOrNot(RRSOCSaving.SECURITY_SUP_NAME_STORE)
|| commonObj.HackerTextExistOrNot(RRSOCSaving.SECURITY_SUP_MOBNO_STORE)
|| commonObj.HackerTextExistOrNot(RRSOCSaving.ALPM_ALPO_NAME)
|| commonObj.HackerTextExistOrNot(RRSOCSaving.ALPM_ALPO_MOBNO))
{
strReturnId = "Something went …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的 blazor 服务器端应用程序上添加导出到 excel 按钮。到目前为止,在梳理互联网之后,这就是我所做的。
我的按钮
<div class="row text-right">
<div class="col-12 p-3">
<button class="btn btn-outline-success" @onclick="@(() =>DownloadExcel(formValues.Region, formValues.startDate, formValues.endDate))">
Export to Excel
<i class="fa fa-file-excel" aria-hidden="true"></i>
</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的 .razor 页面中的方法
public FileResult DownloadExcel(string Region, DateTime StartDate, DateTime EndDate)
{
FileResult ExcelFile = searchService.ExportToExcel(Region, StartDate, EndDate);
return ExcelFile;
}
Run Code Online (Sandbox Code Playgroud)
最后我的服务逻辑
public FileResult ExportToExcel(string Region, DateTime StartDate, DateTime EndDate)
{
var queryable = context.AuditCardPinrecords.Where(s => Region == s.RegionRecordId)
.Where(s => s.AuditComplete == true)
.Where(s => s.DateTime >= StartDate && s.DateTime …Run Code Online (Sandbox Code Playgroud) 我想用它HttpClient来获取我的网页内容。
public async Task<IActionResult> OnGet()
{
NetworkCredential credentials = new NetworkCredential(Settings.Username, Settings.Password);
using (HttpClientHandler handler = new HttpClientHandler { Credentials = credentials })
using (HttpClient httpClient = new HttpClient(handler))
{
Content = await httpClient.GetStringAsync(requestUriString);
}
return Page();
}
Run Code Online (Sandbox Code Playgroud)
问题是我的using语句导致HttpClient和对象在完成HttpClientHandler之前被销毁。GetStringAsync()
我可以删除这些using语句,但我不能保证连接会及时处理。
请注意,HttpClient没有实现IAsyncDisposable,因此使用await using不是一个选项。
如何确保我的 HTTP 对象尽快得到处理,而不是在代码完成之前处理它们?
c# ×9
asp.net ×7
asp.net-core ×2
webforms ×2
.net ×1
.net-core ×1
async-await ×1
blazor ×1
c#-4.0 ×1
calendar ×1
csv ×1
excel ×1
httpclient ×1
jquery ×1
jquery-ui ×1
master-pages ×1
pdf ×1
razor ×1
razor-pages ×1
using ×1