我在javascript中创建一个上传控件,然后element.click()用于调出文件浏览器对话框.
function add(type) {
var element = document.createElement("input");
element.setAttribute("type", type);
element.setAttribute("value", type);
element.setAttribute("name", type);
element.setAttribute("id", "element-" + i);
var removebutton = document.createElement('a');
var removeimage = document.createElement('img');
removeimage.setAttribute("width", 15);
removeimage.setAttribute("height", 15);
removeimage.setAttribute("class", "removebutton");
removeimage.src = "/Content/Images/redx.png";
removebutton.appendChild(removeimage);
removebutton.setAttribute("id", "remove-" + i);
removebutton.setAttribute("onclick", "remove(" + i + "); return 0;");
var newfile = document.getElementById("uploadhere");
//newfile.appendChild(removebutton);
newfile.appendChild(element);
newfile.appendChild(removebutton);
element.click();
i++;
}
Run Code Online (Sandbox Code Playgroud)
文件broswer对话框按预期出现,但在我选择表单上的提交后,任何文件都输入到控件消息中.
如果我单击"浏览",我会收到文件broswer对话框,但文件上传正确.
如何将文件上载控件添加到我的表单,并让它显示文件broswer对话框,仍然按预期工作.
我正在尝试设置我的模型,以便我可以使用它
@Html.EditorFor(e => e.publicationTitle)并让它显示带有提示的水印.
目前我在做
@Html.LabelFor(e => e.PublicationTitle) @Html.TextBox("PublicationTitle",tempTitle.ToString(), new { style = "width:350px", placeholder = "Put title here" })
@Html.ValidationMessageFor(e => e.PublicationTitle)
Run Code Online (Sandbox Code Playgroud)
我发现你可以把[Display(Prompt="Enter title here")]我的模型放进去
但出于某种原因,它并没有出现在我看来.
在旁注.我确实尝试按照这篇文章的说明 Html5占位符与.NET MVC 3 Razor EditorFor扩展?
在这篇文章的最后,它说要更改〜/ Views/Shared/EditorTemplates/String.cshtml文件,但是这个文件不在我的项目中.
任何提示将不胜感激.先感谢您.
跟进!
啊MVC3的乐趣啊.显然,一旦你理解了正在发生的事情,上面的帖子就回答了这个问题.如果在〜/ Views/Shared /文件夹中创建EditorTemplates/String.cshtml文件,则它将使用此模板作为editfor框.
对于其他人来说,简明扼要的最终答案将在下面发布.
我正在构建一个数组,我希望它是一个固定的大小,以便我在一个文件中读取它只存储最后10个命令.该文件似乎正确读取,当我打印它时看起来正确,但由于某种原因我的内存没有被释放.MAX设置为1000,并且较早从用户读取historySize.我在我的代码上运行了valgrind,当对这些函数的调用被注释掉时,我没有任何泄漏.
我的#includes下有一个char**历史
这是我的代码
void setupHistoryFile()
{
char string[MAX];
FILE *fp;
int len;
int pos = 0;
fp = fopen(".ush_history","r");
if(fp == NULL)
{
//create the file
fp = fopen(".ush_history","w");
}
else
{
history = (char**)malloc(historySize * sizeof(char*));//setup history file
fgets(string,MAX,fp);
len = strlen(string);
if(string[len-1]=='\n')
string[len-1]='\0';
while(!feof(fp))
{
if(history[pos] != NULL)
{
free(history[pos]);
history[pos]=NULL;
}
history[pos] = (char*)malloc((strlen(string)+1) * sizeof(char));
//printf("Should be copying %s\n",string);
strcpy(history[pos], string);
pos++;
pos = pos % historySize;
fgets(string,MAX,fp);
len = strlen(string);
if(string[len-1]=='\n')
string[len-1]='\0';
}
}
fclose(fp); …Run Code Online (Sandbox Code Playgroud)