We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Using components in razor view

Hi

Is it possible to use jscript components within asp.net forms which is written with razor engine?

Lets assume I have a form which is created by razor tag helpers and there is field called user id which needs to be implemented as autocompleteTextBox.

Can I get the value from ejAutoCompleteTextbox (js) and set the selected value to asp.net form field?

Or this hybrid approach is bad idea?





1 Reply

AP Arun Palaniyandi Syncfusion Team June 12, 2017 11:44 AM UTC

Hi Tolga, 

 

Thanks for contacting Syncfusion support.   


Is it possible to use jscript components within asp.net forms which is written with razor engine? 
 

Yes, you can use the JavaScript components within asp.net forms which is written with razor engine.  

 

Lets assume I have a form which is created by razor tag helpers and there is field called user id which needs to be implemented as autocompleteTextBox. 

 

Yes, you can implement our Autocomplete using both JavaScript and as html razor tag helpers. Our component will be rendered both ways in the razor page.   

 

 

<div class="form-group"> 

            @Html.LabelFor(model => model.Userid, htmlAttributes: new { @class = "control-label col-md-2" }) 

            <div class="col-md-10"> 

               <h4>ejAutoCompleteTextbox as html razor MVC components</h4> 

                @{ Html.EJ().Autocomplete("Userid").Width("100%").Datasource((IEnumerable<MvcApplication33.Models.AutocompelteDetails>)ViewBag.datasource).WatermarkText("Select a Userid").AutocompleteFields(af => af.Text("Userid")).Render();} 

                @Html.ValidationMessageFor(model => model.Userid, "", new { @class = "text-danger" }) 

            </div> 

        </div> 

 

        <div class="form-group"> 

            @Html.LabelFor(model => model.Address, htmlAttributes: new { @class = "control-label col-md-2" }) 

            <div class="col-md-10"> 

                <h4>ejAutoCompleteTextbox as jscript components</h4> 

                <input type="text" id="Address" /> 

                @Html.ValidationMessageFor(model => model.Address, "", new { @class = "text-danger" }) 

            </div> 

        </div> 

 

<script> 

 

    $(function () { 

 

        $('#Address').ejAutocomplete({ 

            dataSource: states, 

            fields: { key: "index", text: "countryName" }, 

            watermarkText: "Select a Address", 

            width: "100%" 

        

        }); 

    }); 

 

 

</script> 

 

 

Can I get the value from ejAutoCompleteTextbox (js) and set the selected value to asp.net form field? 
 

Yes, you can get the values from both JavaScript and html razor syntax Autocomplete component in the controller. 

 
 
  
 
 
 
 
 

Or this hybrid approach is bad idea? 
 

No, it is not a bad idea to render our Autocomplete control as JavaScript control within asp.net forms with razor engine.   



We have also prepared a sample for your reference below:   

 

https://www.syncfusion.com/downloads/support/forum/130920/ze/AutocompleteForms760525046 

 

 

If the shared details and sample doesn’t meet your requirement, please give us more information to provide an alternative solution.    

    

Regards,
Arun P.    

SIGN IN To post a reply.
Loader.
Live Chat Icon For mobile
Up arrow icon