Jesus A. Jesus A. - 29 days ago 7
Ajax Question

Concat two method calls in javacript

I have method what I use into all my code to populate dropdown lists like:

function FillSelectCatalog(method, controlName, valueName, textName, assignValue) {
try {
$(function () {
$.ajax({
cache: false,
type: "post",
dataType: "json",
url: '../Catalogo/' + method,
contentType: "application/json; charset=utf-8",
success: function (response) {
FillSelect(controlName, response, valueName, textName, assignValue);
},
error: function (response) {
ErrorMessage("Error", GetTextError(response));
}
});
});
} catch (e) {
ErrorMessage("Error", e.message);
}
}


So with jQuery I call my dropdown something like:

FillSelectCatalog("GetActiveMeter", "meterEnergy", "Id", "Meter1", null);


In dropdown I get something like

meterEnegry1,
meterEnergy2,
etc


and I want to concat with another FillSelectCatalog to get something like
"meterEnergy1 - Water"
, is that possible?

There is my another FillSelectCatalog with "Water" value I want to concat:

FillSelectCatalog("GetMeterType", "meterType", "MeterTypeId", "Description", null);


Controller:

[Authorize]
public string GetActiveMeter()
{
string toReturn = string.Empty;
var userId = User.Identity.GetUserId();
var currentUser = UserClass.GetUserBranchOfficeId(userId);
try
{
IGenericRepository<Meter> entity = new GenericRepository<Meter>();
IGenericRepository<MeterType> entity2 = new GenericRepository<MeterType>(); //there is Water value in column Description

var result = entity.GetList(x => x.Status).Where(x => x.BranchOfficeId == currentUser);

toReturn = new JavaScriptSerializer().Serialize(result);
}
catch (Exception ex)
{
throw ex;
}
return toReturn;
}


"Water"
value is into another table called
MeterType
in column called
Description

Regards

Answer
[Authorize]
public string GetActiveMeter()
{
    string toReturn = string.Empty;
    var userId = User.Identity.GetUserId();
    var currentUser = UserClass.GetUserBranchOfficeId(userId);
    try
    {
        IGenericRepository<Meter> entity = new GenericRepository<Meter>();
        var result = entity
          .GetList(x=>x.State)
          .Where(x=>x.BranchOfficeId==currentUser)
          .Select(x=>new { Id = x.Id, Meter1 = x.Meter1 + ' - " + x.MeterType.Description});

        toReturn = new JavaScriptSerializer().Serialize(result);
    }
    catch (Exception ex)
    {
        throw ex;
    }
    return toReturn;
}