我创建了具有3个不同区域的MVC应用程序.(管理员,用户,新闻)这是我在App_Start目录中的RouteConfig.cs文件:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "TestMvcApplication.Controllers" }
);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的AdminAreaRegisteration.cs文件:
namespace TestMvcApplication.Areas.Admin
{
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Admin";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, …Run Code Online (Sandbox Code Playgroud) 我在发布formData到服务器端操作方法时遇到了一些问题.因为ajax调用不会将文件发送到服务器,所以我必须formData手动添加文件上传器数据,如下所示:
var formData = new FormData();
formData.append("imageFile", $("#imageFile").file);
formData.append("coverFile", $("#coverFile").file);
Run Code Online (Sandbox Code Playgroud)
我编写了jQuery函数,需要使用ajax调用将表单数据发布到服务器.它的工作原理,但formData在服务器端发布始终为空!
这是我的脚本:
<script>
function SubmitButtonOnclick()
{
var formData = new FormData();
formData.append("imageFile", $("#imageFile").file);
formData.append("coverFile", $("#coverFile").file);
$.ajax({
type: "POST",
url: '@Url.Action("EditProfile", "Profile")',
data: formData,
dataType: 'json',
contentType: "multipart/form-data",
processData: false,
success: function (response) {
$('#GeneralSection').html(response.responseText);
},
error: function (error) {
$('#GeneralSection').html(error.responseText);
}
});
}
</script>
Run Code Online (Sandbox Code Playgroud)
编辑1: 这是控制器中的操作方法:
public ActionResult EditProfile(ProfileGeneralDescription editedModel,
HttpPostedFileBase imageFile,
HttpPostedFileBase coverFile,
string postOwnerUser)
{
try
{
if (postOwnerUser == User.Identity.Name)
{ …Run Code Online (Sandbox Code Playgroud) 我在SQL Server 2008 R2中有一个包含两个字段(WordHash,Word)的表.Hash在C#中生成此字段,我需要为Wordsql server中的字段重新生成哈希码.
但我的问题是在sql server和C#中生成的MD5哈希是不同的.我发现下面的代码来解决这个问题,但我仍然遇到同样的问题.
SQL代码:
CONVERT(NVARCHAR(32),HASHBYTES('MD5', 'some word'), 2)
Run Code Online (Sandbox Code Playgroud)
将此代码块放入查询后,我看到了一些有线结果!这是我的结果:
我的查询:
SELECT
[WordHash],
convert(nvarchar(32),HASHBYTES('MD5', 'Analytics'),2) AS TestHash,
convert(nvarchar(32),HASHBYTES('MD5', [Word]),2) AS SqlHash
FROM myTable
Run Code Online (Sandbox Code Playgroud)
结果:
WordHash: A768CAA988605A2846599CF7E2D0C26A
TestHash: A768CAA988605A2846599CF7E2D0C26A
SqlHash F4AFA5FEF805F7F5163EC6402BAF61FF
Run Code Online (Sandbox Code Playgroud)
请注意,它'Analytics'是数据库中的记录数据之一.
为什么TestHash&SqlHash虽然他们来自同一个代码生成是不同的!?
我写了一个像这样的局部方法:
public ActionResult _StatePartial()
{
ViewBag.MyData = new string[] { "110", "24500" };
return View();
}
Run Code Online (Sandbox Code Playgroud)
并_StatePartial在_Layout页面中渲染视图:
@Html.Partial("_StatePartial")
Run Code Online (Sandbox Code Playgroud)
这是我的部分视图代码:
@{
string[] Data = (string[])ViewBag.MyData;
}
<div id="UserState">
Reputation: @Html.ActionLink(Data[0], "Reputation", "Profile") |
Cash: @Html.ActionLink(Data[1], "Index", "FinancialAccount")
</div>
Run Code Online (Sandbox Code Playgroud)
但是当我运行这个项目时,_ StatePartial方法不会调用并且ViewBag始终为null.
Server Error in '/' Application.
Object reference not set to an instance of an object.
Run Code Online (Sandbox Code Playgroud)
请注意,这些参数不是我的模型字段,而是通过调用Web服务方法进行计算.但我不断在我的问题中设定这些价值.
我能为此做些什么?是否有将参数传递给局部视图的想法?谢谢.