asp.net mvc 3 - MVC3 search usercontrol -



have partial view in website, shared among many pages, searching functionality, consisting of:
date
date
file type
file name

now,the problem is, in pages dont want file type included, in other pages dont want (from-to) date criteria included

what should do? should create partial view each functionality? or show/hide criteria within?

_filters.cshtml

@model entities.filteroperations <table width="85%" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td class="formtit"> start date </td> </tr> <tr> <td>@html.textboxfor(m => m.startdate, new { @class = "date" }) </td> </tr> <tr> <td class="formtit"> end date </td> </tr> <tr> <td>@html.textboxfor(m => m.enddate, new { @class = "date" }) </td> </tr> <tr> <td class="formtit"> file type </td> </tr> <tr> <td>@html.textboxfor(m => m.filetype) </td> </tr> <tr> <td class="formtit"> file name </td> </tr> <tr> <td>@html.textboxfor(m => m.filename) </td> </tr> <tr> <td align="right"> <input type="submit" value="search" /> </td> </tr> </table> 

just add few properties filteroperations model like:

public bool renderfiletype {get; private set;} public bool renderdateto {get; private set;} 

with new ctor:

public filteroperations(bool renderfiletype = true, bool renderdateto = true) { renderfiletype = renderfiletype; renderdateto = renderdateto; } 

now can set conditions in partial so:

@if(model.renderfiletype) { <tr> <td>@html.textboxfor(m => m.filetype) </td> </tr> } 

then in view call partial so:

@html.partial("_filters.cshtml", new filteroperations(renderdateto: false)) 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -