小编Mon*_*set的帖子

MVC 5 上传文件 (POST) 和一个附加参数

我正在使用这个简单的教程在我的 MVC5 C# VS2015 项目中上传文件,并且在控制器操作中不需要额外的参数,文件被成功上传。这是控制器操作

    [HttpPost]
    public string UploadFile(HttpPostedFileBase file)
    {
        if (file.ContentLength <= 0)
            throw new Exception("Error while uploading");

        string fileName = Path.GetFileName(file.FileName);
        string path = Path.Combine(Server.MapPath("~/Uploaded Files"), fileName);
        file.SaveAs(path);
        return "Successfuly uploaded";
    }
Run Code Online (Sandbox Code Playgroud)


和视图的上传表单

@using (Html.BeginForm("UploadFile", "Documents", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.TextBox("file", "", new { type = "file" })
    <input type="submit" value="Dodaj fajl" />
}  
Run Code Online (Sandbox Code Playgroud)

在那个视图中,我有另一个名为 的变量DocumentNumber,我需要将其传递给UploadFile操作。我只是猜测我的动作的标题看起来像这样:public string UploadFile(HttpPostedFileBase file, int docNo)如果我想传递那个变量,但我也不知道如何在视图的表单中设置这个值。我尝试添加:new { enctype = …

c# asp.net-mvc post webforms

5
推荐指数
1
解决办法
8227
查看次数

继承不按预期工作

班级Enemy,Ore是班级的孩子Entity.上课Asteroid是孩子的Enemy.当我的船接触任何实体时,会触发以下代码.

几句话的代码是:当船舶接触矿石时,将矿石添加到船舶的库存中并从筛网中移除该矿石.当船接触敌人时,检查它是什么敌人.如果它是小行星,请向后推船,降低它的健康状况并删除该小行星.

if (entities[j] is Ore)
{ pilots[i].Ship.InventoryAdd(entities[j]); entities.RemoveAt(j--); }

if (entities[j] is Enemy)
{
    if(entities[j] is Asteroid)
    {
        pilots[i].Ship.AddForce(entities[j].Force * (entities[j] as Enemy).Damage);
        pilots[i].Ship.HP -= (entities[j] as Enemy).Damage;
        entities.RemoveAt(j);
    }
}
Run Code Online (Sandbox Code Playgroud)

请注意,我看到在一次更新或框架中可以触发的问题,两次碰撞都在发生(船舶与小行星和船舶与矿石),我将解决这个问题.此外,这是整个代码,而不仅仅是所有情况的一部分.现在,我只在屏幕上有矿石和小行星(和一艘船).

船舶与矿石碰撞中出现了问题.我的船被推回去了.但我只在船上与小行星上做到这一点.这意味着该计划将矿石视为小行星,而不是.我多次检查了所有这些东西.是的,他们都有相同的父母,但如果我问一个实例是否是小行星,他怎么能说"是的,而且它也是一个矿石",当它不是时.

如果我要求一个Asteroid实例,如果它是Entity and Enemy和Asteroid类,我会得到答案,我总是得到一个答案"是",但是Ore怎么能成为小行星呢?

问题是:这背后的逻辑什么,如何以正确的方式检查?还要注意,增加力量的线将为所有敌人射击,而不仅仅是小行星,这是现在的情况.

c# inheritance class typeof

-7
推荐指数
1
解决办法
114
查看次数

标签 统计

c# ×2

asp.net-mvc ×1

class ×1

inheritance ×1

post ×1

typeof ×1

webforms ×1