Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
var a = [];
var b=[];
@foreach (var filename in Model.File)
{
    @:a.push('@filename');
}
@foreach (var errortext in Model.Error)
{
    @:b.push('@errortext');
}



The above gives me :
a[0]="File1";
a[1]="File2";
b[0]= "Unable to open report attachment [iRefpdfFile.PDF]. This will not adversely affect the submission of this file online in any way. Error: Cannot handle iref streams. This PDF will need to be resaved in an Acrobat 5 compatable manner or with the original save options changed so that it does not to use this feature."
b[1]="This is a demo error message."


The sequence of filename and error is maintained that is b[0] is a[0]'s error message.
But i want to display alert for every file and its consequtive error message. How do i do that ?

What I have tried:

I tried to perform @foreach loop but that doesnt allow me to use alert keyword or any javascript method .
Note the code is inside <script> tag and not inside <script type="text/javascript">
Posted
Updated 21-Nov-16 18:48pm
v5
Comments
Patrice T 22-Nov-16 0:50am    
This is a completely different question.
Please don't do this, open new question instead.
Abrar Kazi 22-Nov-16 1:15am    
ok

1 solution

The inArray[^] method expects an array as its second parameter. You are passing a string.

To find the index of a substring within the string, use indexOf[^]:
JavaScript
var texttosearchfrom = a[0];
var found = texttosearchfrom.indexOf('Acrobat');

If you want a case-insensitive match, then use search[^] with a case-insensitive Regular Expression[^] :
JavaScript
var texttosearchfrom = a[0];
var found = texttosearchfrom.search(/Acrobat/i);
 
Share this answer
 
Comments
Abrar Kazi 22-Nov-16 0:14am    
Thanks it helped.
I have updated my question please look into it and help. thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900