[英]Send button from c# to client side
I have a helper created as follows:- 我有一个创建如下的助手:
public static MvcHtmlString FileDomElement(this HtmlHelper helper, FileUpload fileUpload)
{
string strOutput = string.Empty;
if (fileUpload.MultipleFile)
{
if (string.IsNullOrEmpty(fileUpload.MimeType))
{
strOutput = "<input type=\"file\" multiple=\"multiple\" id=\"chooseFiles\" value=\"Choose File(s)\" onchange=\"ehDisplayFileNames();\" style=\"opacity: 0\" >";
}
else
{
strOutput = "<input type=\"file\" multiple=\"multiple\" id=\"chooseFiles\" value=\"Choose File(s)\" accept=\"" + fileUpload.MimeType + "\" onchange=\"ehDisplayFileNames();\" style=\"opacity: 0;\">";
}
}
else
{
if (string.IsNullOrEmpty(fileUpload.MimeType))
{
strOutput = "<input type=\"file\" id=\"chooseFiles\" value=\"Choose File(s)\" onchange=\"ehDisplayFileNames();\" style=\"opacity: 0;\">";
}
else
{
strOutput = "<input type=\"file\" id=\"chooseFiles\" value=\"Choose File(s)\" accept=\"" + fileUpload.MimeType + "\" onchange=\"ehDisplayFileNames();\" style=\"opacity: 0;\">";
}
}
return MvcHtmlString.Create(strOutput);
}
Now in the onchange event of the file I want to send the button to the backend. 现在,在文件的onchange事件中,我想将按钮发送到后端。 Because I have multiple file input elements on a single page.
因为我在单个页面上有多个文件输入元素。 So I want to detect which one was clicked.
因此,我想检测单击了哪个。
Please help me with this. 请帮我解决一下这个。
Thanks Abhishek 感谢Abhishek
You could try catching the event info and using that to get a reference to the sender: 您可以尝试捕获事件信息,并使用它来获取对发送者的引用:
function ehDisplayFileNames(event) {
console.log(event.target.id + ' has fired the event!');
}
Your markup would need to send the event: onchange="ehDisplayFileNames(event);" 您的标记将需要发送事件:onchange =“ ehDisplayFileNames(event);”
Mark's comment above is very true, once you have a client side id you will still need some type of Ajax call to get this info back to the server. 马克的上面的评论非常正确,一旦有了客户端ID,您仍将需要某种类型的Ajax调用才能将该信息返回给服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.