这个问题可能很荒谬,对不起.
哪个事件最适合阅读会话数据 - Page_Load或Page_Init事件?
目前我正在使用Page_Load事件来执行此类任务.但我在一篇文章中看到过要做的Page_Init事情.
谢谢.
更新:http://csharpdotnetfreak.blogspot.com/2008/11/detecting-session-timeout-and-redirect.html
我有以下代码在xml文件中写入一些数据.它运作良好,但属性.我无法为元素创建属性及其值.
//.xml file===========================
<?xml version="1.0" encoding="utf-8"?>
<Errors>
<Error Name="abc" ContactNo="123">
<Description>Test</Description>
</Error>
</Errors>
// c# code ===========================
XmlDocument xmlErrors = new XmlDocument();
xmlErrors.Load(Path.Combine(Application.StartupPath, "Errors.xml"));
XmlElement subRoot = xmlErrors.CreateElement("Error");
// subRoot.Attributes[0].Value = "Test 1";
// subRoot.Attributes[1].Value = "Test 2";
XmlElement Description = xmlErrors.CreateElement("Description");
Description.InnerText = currentData.ExamineeName;
subRoot.AppendChild(Description);
xmlErrors.DocumentElement.AppendChild(subRoot);
xmlErrors.Save(Path.Combine(Application.StartupPath, "Errors.xml"));
Run Code Online (Sandbox Code Playgroud)
你能帮我提一下如何创建属性及其价值吗?谢谢.
在我的ASP.Net MVC 4项目中,我在控制器文件夹的子文件夹中有一个控制器 -
/Controllers
/GroupA
/AbcController.cs
Run Code Online (Sandbox Code Playgroud)
在AbcController中,我有两种方法 -
public ActionResult Index()
{
return View();
}
public ActionResult Edit(string value)
{
ViewBag.Message = value;
return View();
}
Run Code Online (Sandbox Code Playgroud)
RouteConfig.cs -
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "TestRoute",
url: "GroupA/{controller}/{action}/{id}",
defaults: new { controller = "AbcController", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Run Code Online (Sandbox Code Playgroud)
但是当我浏览 http://localhost:2240/groupa/abc/edit/somevalue
,'somevalue'不会传递给方法.它显示为null.
我在这里缺少什么?
我需要重置几个 select2 选择元素。目前我正在这样做
$("#ItemId").select2("val", "");
$("#PermanentDistrictId").select2("val", "");
$("#PermanentThanaId").select2("val", "");
$("#PresentDistrictId").select2("val", "");
$("#PresentThanaId").select2("val", "");
$("#OccupationId").select2("val", "");
$("#GenderId").select2("val", "");
Run Code Online (Sandbox Code Playgroud)
但我想用单个函数来完成它,如下所示-
ParticularForm.AllSelectElements.select2("val", "");
Run Code Online (Sandbox Code Playgroud)
我在这里问是因为我的javascript技能很差。所以,我需要你的帮助。
谢谢。
我正在尝试将一些数据从 html 页面发送到 mvc 控制器。它通过 ajax 作为 FormData 发送,并在控制器中作为 FormCollection 进行处理。其中一个元素是对象数组。我如何在控制器中检索这个数组?
client code================
var products = []
$('tr').each(function () {
var row = $(this);
var product = {};
product.Id = row.find('.id').val();
product.Id = row.find('.quantity').val();
products.push(product);
});
var data = new FormData();
data.append('PersonId', pid);
data.append('SubmitDate', sdate);
data.append('Products', products);
Server code=================
[HttpPost]
public ActionResult SalesData(FormCollection data)
{
String personId=data["PersonId"].ToString();
String submitDate=data["SubmitDate"].ToString();
//how to retrieve Products ??
}
Run Code Online (Sandbox Code Playgroud)
有什么帮助吗?
谢谢。
在我的ASP.NET MVC项目中,我使用ClosedXML生成了一个excel文件.
它在非ajax调用中运行良好.这是我的控制器动作方法
// Prepare the response
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=\"" + reportHeader + ".xlsx\"");
// Flush the workbook to the Response.OutputStream
using (MemoryStream memoryStream = new MemoryStream())
{
MyWorkBook.SaveAs(memoryStream);
memoryStream.WriteTo(Response.OutputStream);
memoryStream.Close();
}
Response.End();
Run Code Online (Sandbox Code Playgroud)
现在我试图通过ajax请求来做到这一点.但该文件不是从mvc控制器发送的.
$.ajax({
url: url,
type: "POST",
data: fd,
processData: false,
contentType: false,
beforeSend: function () {
},
success: function (response) {
},
error: function (request, status, error) {
},
complete: function () {
}
});
Run Code Online (Sandbox Code Playgroud)
我怎么能完成它?先感谢您.
我的应用程式中有以下POCO类别-
public class Course
{
public String Title { get; set; }
public String Description { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
但是Coursemongodb中的集合还包含其他一些字段。我正在尝试获取数据,如下所示:
var server = MongoServer.Create(connectionString);
var db = _server.GetDatabase("dbName");
db.GetCollection("users");
var cursor = Photos.FindAs<DocType>(Query.EQ("age", 33));
cursor.SetFields(Fields.Include("a", "b"));
var items = cursor.ToList();
Run Code Online (Sandbox Code Playgroud)
我从stackoverflow的这篇文章中获得了该代码。
但这引发了一个例外-
"Element '_id' does not match any field or property of class"
Run Code Online (Sandbox Code Playgroud)
我不需要POCO中的“ _id”字段。有什么帮助吗?
我对在方法层次结构中处理异常有点困惑.
比方说,我是Logger一个类库项目中的一个类.请看下面的代码 -
namespace MyLibrary
{
public class Logger
{
//exposed to other project
public static void CreateLog(String message)
{
try
{
WriteInFile(message); //calling the method below
}
catch (Exception Ex)
{
throw Ex;
}
}
//private method
private static void WriteInFile(String message)
{
try
{
//Writing in a file
}
catch (Exception Ex)
{
throw Ex;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我们假设,我在ASP.NET MVC项目中使用该库.代码 -
namespace MvcProject.Controllers
{
public class HomeController : Controller
{
public ActionResult DoSomething()
{
try …Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习ASP.NET Core 2 MVC应用程序。
接受新项目后,在解决方案资源管理器中看不到任何web.config文件。
有什么帮助吗?
抱歉,这是一个愚蠢的问题。
我的应用程序中有一个循环.代码如下: -
foreach (DataRow dr in dt.Rows)
ColorNames +=dr["ColorName"].ToString() + "\n";
Run Code Online (Sandbox Code Playgroud)
但我不想\n在最后添加Datarow.有什么建议怎么办?