c# - Using Guid as an optional parameter gives 'parameter requires a value of type 'System.Nullable' -


i had linking model viewmodel in controller - seems work. here code:

public actionresult techsearchknowledgebase([optional]guid? createdbyid, [optional]guid? categoryid, [optional]guid? typeid)         {              var model = db.knowledgebases.asqueryable();              if (createdbyid != guid.empty)             {                 model = model.where(k => k.createdbyid == createdbyid);                 viewbag.createdby = db.users.where(c => c.userid == createdbyid).first().fullname;             }             if (categoryid != guid.empty)             {                 model = model.where(k => k.categoryid == categoryid);                 viewbag.category = db.categories.where(c => c.categoryid == categoryid).first().categoryname;             }             if (typeid != guid.empty)             {                 model = model.where(k => k.typeid == typeid);                 viewbag.category = db.roles.where(c => c.roleid == typeid).first().roledescription;             }             model=model.orderby(k => k.createddate);              list<knowledgebaseresult> knowledgebaseresults = mapper.map<list<knowledgebaseresult>>(model.tolist());              return view("techknowledgebaselist", knowledgebaseresults);          } 

i have issues code though:

if load error:

the parameters dictionary contains invalid entry parameter 'categoryid' method 'system.web.mvc.actionresult techsearchknowledgebase(system.nullable1[system.guid], system.nullable1[system.guid], system.nullable1[system.guid])' in 'helpdesk.webui.controllers.knowledgebasecontroller'. dictionary contains value of type 'system.reflection.missing', parameter requires value of type 'system.nullable1[system.guid]'. parameter name: parameters

i not familiar syntax being used declare optional parameters in techsearchknowledgebase method. depending on trying do, try 1 of following:

1) remove [optional] tags. method this:

techsearchknowledgebase(guid? createdbyid, guid? categoryid, guid? typeid) 

these nullable guid parameters, , call method techsearchknowledgebase(null, null, null); meet needs?

2) if require optional parameters, review named , optional arguments. can see therein optional parameters declared after required parameters, , have default value specified. since using guids, guess don't want these optional parameters, or want specify guid.empty default value. if latter true, method definition like:

public actionresult techsearchknowledgebase(guid? createdbyid = guid.empty, guid? categoryid = guid.empty, guid? typeid = guid.empty) 

if misunderstanding problem, please clarify , provide code calling method.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -