locked
Convert Code JavaScript To C# RRS feed

  • Question

  • User-19694853 posted

    i have function javascrip like this

    function save_blob_image() {
    var blob_images = [];
    var desc_images = [];
    var exifObj;
    var exifStr;
    
    document.getElementById('blob_image_1').value = '';
    try {
    	 
    	$('#blob_image_1').val($image_1);
    
    }
    catch (err) {
    	// console.log(err);
    }
    blob_images.push($('#blob_image_1').val());
    
    if ($('#desc_image_1').val()) {
    	desc_images.push($('#desc_image_1').val());
    } else {
    	desc_images.push('');
    }
    
    document.getElementById('blob_image_2').value = '';
    try {
    	
    	$('#blob_image_2').val($image_2);
    
    }
    catch (err) {
    	// console.log(err);
    }
    blob_images.push($('#blob_image_2').val());
    
    if ($('#desc_image_2').val()) {
    	desc_images.push($('#desc_image_2').val());
    } else {
    	desc_images.push('');
    }
    
    document.getElementById('blob_image_3').value = '';
    try {
    	// original: e.target.result
    
    	$('#blob_image_3').val($image_3);
    
    }
    catch (err) {
    	// console.log(err);
    }
    blob_images.push($('#blob_image_3').val());
    
    if ($('#desc_image_3').val()) {
    	desc_images.push($('#desc_image_3').val());
    } else {
    	desc_images.push('');
    }
    
    return [blob_images, desc_images];
    }

    i need to convert to C#, thanks so much

    Sunday, September 16, 2018 3:43 AM

All replies

  • User409696431 posted

    The way this forum works is that you tell us what you've tried, show us the code, and tell us what result you were trying to get and what result you actually get.

    It's not really a a free code translation service.

    In your case, since JavaScript runs on the user's computer and C# runs on the server, the first thing you need to do is translate your requirements: what is it doing now, on the user's computer, and what do you want to do on the server, instead?

    Sunday, September 16, 2018 4:36 PM
  • User-893317190 posted

    Hi zjm_zjm,

    Javascript runs at client side and operate dom. C# runs at server side and it couldn't operate dom.

    So your code relating to dom operation won't work using c#.

    You couldn't find corresponding code operateing dom in c#.

    Best regards,

    Ackerly Xu

    Monday, September 17, 2018 6:41 AM
  • User-19694853 posted

     i don't  know  in this code 

    return [blob_images, desc_images];

    in C# how to implement like this. thanks

    Sunday, September 23, 2018 9:41 AM
  • User-893317190 posted

    Hi zjm_zjm,

    It seems that you want to return an array with two arrays as its elements.

    If so , you could use c# list. Below is my code.

     List<List<string>> total = new List<List<string>>();
    
                List<string> blob_images = new List<string>();
                List<string> desc_images = new List<string>();
    
                blob_images.Add("image1");  //blob_images.push($('#desc_image_3').val());
                desc_images.Add("desc-image1"); //desc_images.push($('#desc_image_1').val());
    
                total.Add(blob_images);
                total.Add(desc_images);
                return total;

    If you want to store data whose type is int. Just change to  List<List<int>> and so on.

    Best regards,

    Ackerly Xu

    Monday, September 24, 2018 1:32 AM