c# - Parameters dictionary contains a null entry for parameter -
i having 2 view pages using same controller , model way change page layout having trouble displaying second page. error message: the parameters dictionary contains null entry parameter id of non-nullable type method system.web.mvc.actionaresult listview(int32) in usercontroller
not sure causing problem used same code first view page(working) except changing view layout.
first view
<div> <a href="/roster/listview">click here list view</a> </div> <section id="users" data-bind="foreach: users"> <div id="nameimage"> <figure id="content"> <img width="158" height="158" alt="gravatar" data-bind="attr:{src: gravatarurl}"/> <figcaption> <a title="email" id="emailicon" class="icon-envelope icon-white" data-bind="attr:{'href':'mailto:' + email()}"></a> <a title="profile" id="profileicon" class="icon-user icon-white"></a> </figcaption> </figure> <p data-bind="text:name"></p> </div> </section> </section>
list view
<div class="accordion-inner"> <div data-bind="foreach: users"> <div> <img width="158" height="158" alt="gravatar" data-bind="attr:{src: gravatarurl}"/> <p data-bind="text:name"></p> </div> </div>
controller
public actionresult view(int id) { // menu cache, id viewbag.sidebarmenu = sidemenumanager.getrootmenu(id); viewbag.userapiurl = "/api/user/" + id.tostring(); return view(); } public actionresult listview(int id) { // menu cache, id viewbag.sidebarmenu = sidemenumanager.getrootmenu(id); viewbag.userapiurl = "/api/user/" + id.tostring(); return view(); } }
api controller
private userservice _userservice = new userservice(); public ienumerable<user> get(int? id) { if (id.hasvalue) { return _userservice.getusers(id.value); } throw new httpresponseexception(httpstatuscode.notfound); }
the url /roster/listview
missing id value. you'll need either:
- change url
/roster/listview/123
- change action method allow nullable integer changing type
int
int?
. in action method need check ifid
parameter null or not , deal appropriately, such returning error, or ignoring id.
Comments
Post a Comment