[英]How to send error message from C# to Ajax to use this error message's content in client side?
[英]Send button from c# to client side
我有一個創建如下的助手:
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);
}
現在,在文件的onchange事件中,我想將按鈕發送到后端。 因為我在單個頁面上有多個文件輸入元素。 因此,我想檢測單擊了哪個。
請幫我解決一下這個。
感謝Abhishek
您可以嘗試捕獲事件信息,並使用它來獲取對發送者的引用:
function ehDisplayFileNames(event) {
console.log(event.target.id + ' has fired the event!');
}
您的標記將需要發送事件:onchange =“ ehDisplayFileNames(event);”
馬克的上面的評論非常正確,一旦有了客戶端ID,您仍將需要某種類型的Ajax調用才能將該信息返回給服務器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.