我已经完成了使用表单将照片上传到MVC(照片作为参数发送到AJAX CALL)控制器的测试,现在需要做同样但修改过:
有效的原始来源是:
<form action="/Home/Upload" method="post" enctype="multipart/form-data">
<label for="photo">Photo:</label>
<input type="file" name="photo" id="photo" />
<input id="uploadbtn" type="submit" value="Upload" />
</form>
Run Code Online (Sandbox Code Playgroud)
和Controller的动作代码:
[HttpPost]
public ActionResult Upload(HttpPostedFileBase photo)
{
// Verify that the user selected a file
if (photo != null && photo.ContentLength > 0)
{
// extract only the fielname
var fileName = Path.GetFileName(photo.FileName);
// store the file inside ~/App_Data/uploads folder
var path = Path.Combine(Server.MapPath("~/C:/poze"), fileName);
photo.SaveAs(path);
}
return Json(new { Success = true });
}
Run Code Online (Sandbox Code Playgroud)
这有效,但在这种情况下不起作用:
@using (Html.BeginForm(null, null, FormMethod.Post, …Run Code Online (Sandbox Code Playgroud) 我需要在我的网页中添加1个文本框事件(使用C#在ASP.NET中创建),并在Page_Load函数和asp语法中声明:
protected void Page_Load(object sender, EventArgs e)
{
textbox1.TextChanged += new EventHandler(textbox1_TextChanged);
}
public void textbox1_TextChanged(object sender, EventArgs e)
{
if (textbox1.Text == "ABCD")
{
Image1.Visible = true;
textbox1.Enabled = false;
}
}
Run Code Online (Sandbox Code Playgroud)
进入asp页面我使用了这个声明:
<asp:TextBox Width="200" ID="textbox1" runat="server"></asp:TextBox>
Run Code Online (Sandbox Code Playgroud)
我做了调试,发现没有执行textbox1_TextChanged函数
为什么?
我有这个代码
<a href="~Home.aspx">
<img style="float:left;margin-left:1px;" src=~img/head/acasa.png
title="Acasa" />
</a>
Run Code Online (Sandbox Code Playgroud)
当我启动项目时,VS会返回此错误" 错误38无法使用前导..退出顶层目录."
问题是什么?
此代码是控件*ascx的一部分