1
I have the following code in a Razor view:
<div id="HTMLreturned" class="row">
@Html.Raw(ViewBag.HTMLreturned);
</div>
<script>
var nrLinks = 0;
$(".enlacesMas > a").each(function(){
nrLinks++;
var link = "http://www.meu.site" + $(this).attr('href').replace("..","");
// Agora preciso de guardar todos os link num array ou algo do género
});
</script>
In the controller
put in the Viewbag.Htmlreturned the result of this line:
ViewBag.HTMLreturned = WebClient.client.DownloadString(meuUrl)
How can I run my code view
in my controller
to keep each href in variable C#?
Obs:
The html
which jQuery works with is rendered before the script is executed, so these classes are from html
within the viewbag
What do you mean, young man? Explain better what you want to do.
– Jéf Bueno
@jbueno I think it’s clearer now
– ihavenokia
After running each, you want to store all href in an array and return it to a controller. This?
– Aline
@Aline, I don’t want to have a
view
at all, I want to do it all incontroller
– ihavenokia
Yeah, I didn’t quite understand.
– Aline
I realized now that what I wanted to do is not going to be possible, basically what I need now to turn this jQuery code into code c#
– ihavenokia
Can you explain why you wanted to use backend code instead of Jquery? What was your use case?
– Not The Real Hemingway
I had a string that was an html, and I wanted to extract information from it using a language like jQuery, because I already know some techniques
– ihavenokia