asp.net mvc - Design | maintainable | conditionals view | MVC -


have view need show address details in view

name street state , city, washington 

now sequence of address needs differ each country china want below format

name state , city, washington street 

so have done written if else statement in view , have format , earlier have no issues 1 or 2 countries

but seeing same kind of different request each countries, make view heavy , not maintainable

can provide pattern have more maintainable 1 have different partial view each country , load partial view etc

ok best option have different views different countries , return them controller based on identifier.this keep code maintainable.for sure dont use if - else. can create multiple partial views each country if not fields dynamically sequenced.keep static ones on main view , dynamic in partial view.

now if have far many countries , don't want maintain individual views option create htmlhelper extension , use create view dynamically in code , return mvchtmlstring can used in view shown below.

 @html.countryfields('us') 

edit:

also check below link may useful in scenario (good example of using multiple views mentioned above)

http://brianreiter.org/2011/03/23/simple-asp-net-mvc-globalization-with-graceful-fallback/


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -