Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a CountryIdHiddenField and I want to pass the CountryIdHiddenField.Value to the below Function.

public string GetCountriesPdf(Entities.Masters.Country country)
{
string FilePath = ConfigurationManager.AppSettings["GetCountriesPdf"];

switch(country.Id)
{
case 1:
return FilePath+= "Country file";
}
}


What I have tried:

I have tried to pass like:

string Val = CountryIdHiddenField.Value;

Country_Bal country = new Country_Bal();

country.GetCountriesPdf(Val); //throwing an error here, that cannot pass this string to Entities.Masters.Country
Posted
Updated 30-Aug-20 18:41pm

Quote:
country.GetCountriesPdf(Val); //throwing an error here, that cannot pass this string to Entities.Masters.Country

You are trying to pass a string when you have defined a method that takes Entities.Masters.Country Type as a parameter.

Don't think it's related to hidden field here. It's more of how to pass the string here. Given you know your entity definition, you need to convert this string into the expected entity and then call the GetCountriesPdf method.
 
Share this answer
 
If you have the id you'll need to get the Country object from the database context so that you can pass it to the function.

C#
var id = int.Parse(CountryIdHiddenField.Value);
Country country = dbContext.Countries.FirstOrDefault(c => c.Id == id);
string path = GetCountriesPdf (country);
 
Share this answer
 
The code you show (not what you tried) would actually work if:

an instance of Entities.Masters.Country has a valid integer field or property named 'Id.

Without knowing the Type and structure of the hidden field, its relation to Entities.Masters.Country, and how you use/access it ... can't say more.
 
Share this answer
 

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