asp.net mvc 4 - How to disable TextAreaFor? -


how disabled text in mvc. using mvc 4.0. below code, want make conditionally means if m.changes values length >0 should disable,else enabled. how possible?

@html.textareafor(m => m.changes , new { style = " width:97%; height:50px;", tabindex = 5 })  

conditional disabling possible using javascript. first, need set id:

@html.textareafor(m => m.changes , new { style = " width:97%; height:50px;", tabindex = 5, id = "someid" })  

and assuming use jquery:

$('#someid').on('keyup', function() {     var text = $('#someid').val();     if (text.length > 0)       $('#someid').attr('disabled','disabled'); }); 

i'd note, however, disabling textbox when length of it's content greater zero, is, has content, makes no sense, since disabling prevent modifying ever again (unless there logic programmatically re-enables based on condition).

if goal disable control if length of value on server greater 0 (that is, changes property has not null , non-empty value inside model), this:

@if (model.changes.length > 0) {    @html.textareafor(m => m.changes , new { style = " width:97%; height:50px;", tabindex = 5, id = "someid", disabled = "disabled" })  } else {    @html.textareafor(m => m.changes , new { style = " width:97%; height:50px;", tabindex = 5, id = "someid" })  } 

if need disable based on client-side condition, can't avoid writing scipt that.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -