What you are probably wanting to do is this:
public bool post(T model,Int id)
{
if(model is candidatecomment)
{
((candidatecomment)model).candidateId = id;
}else
{
((jobcomment)model).jobid = id;
}
}
[Edit]
To answer your other question, yes, there is a way to disable type checking at runtime, but its a bit dirty:
public bool post(dynamic model,Int id)
{
if(model is candidatecomment)
{
model.candidateId = id;
}else
{
model.jobid = id;
}
}
The keyword
dynamic
basically means that the compiler will not check the type of the data until runtime. This is dirty because Intellisense won't work on the model (so typing model. won't bring up a hint menu), and you have to get the spelling and capitalization right by memory. I would avoid this in favor of the one on top.