0

//Controller

public Label CallbackPanelPartial()       
{    
     Label rb = new Label();`
     rb.ID = "dd";
     rb.Text = "aaa";       
     return rb; 
}

jQuery function to bind label as html content to view

function LoadFormGen(s,e) 
{

        $.ajax({
            type: "POST",
            url: '@Url.Action("CallbackPanelPartial", "LoadForm")',
            beforeSend: function () {
                lpTimeslot.Show();
            },
            success: function (response) {
                $("#genForm").html(response);

                    pcTimeslotHed.SetHeaderText('Load - [New]');

                pcTimeslotHed.Show();
                lpTimeslot.Hide();
            }
        });
    }

I'm getting a result as System.Web.UI.WebControl.Label. What I want is to get the html content returned label.

1
  • System.Web.UI.WebControl.Label is web forms, not MVC! Commented Jul 3, 2015 at 22:50

1 Answer 1

1

Label class will always return an Object not HTML

If you want to get HTML then

First Create an ActionResult which will return a Partial View with Label class Model. assign value accordingly

public ActionResult CallbackPanelPartial()       
{    
 Label rb = new Label();`
 rb.ID = "dd";
 rb.Text = "aaa";
 return PartialView(rb );
}

Create a Partial View with name CallbackPanelPartial.cshtml which will accept System.Web.UI.WebControl.Label type model

@model System.Web.UI.WebControl.Label
    @{

    }
    <Label id = "@Model.ID">@Model.Text</Label>

Else code will remain same

Sign up to request clarification or add additional context in comments.

4 Comments

I want to add labels dynamically to the view according to the database value. That's why I have created Label in the controller.
I have made some changes in answer that will create lable dynamic as per model which you will send
How to use panel instead of label for the same scenario where two labels are there inside the panel
Will you please describe in detail what do you want ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.