How to display tooltip for textbox while user entering value using asp.net mvc without using jquery/client script? I tried using @Html.TextBoxFor and title. but it was not working.

I have a SelectList that populates / works ok.

I have a new Requirement to disable the list for certain users. So I added in a new property to the ViewModel, LockSelectList. this property is set in the controller (and works).

However, when the list is rendered, it is always disabled.

I have tried

@Html.DropDownListFor(x => x.Id,  Model.AllLocations, new {disabled = Model.LockLocationList? "true" : "false" })

@Html.DropDownListFor(x => x.Id,  Model.AllLocations, new {disabled = Model.LockLocationList? "disabled" : "false" })

@Html.DropDownListFor(x => x.Id,  Model.AllLocations, new {disabled = Model.LockLocationList? "disabled" : "" })

but none work. they all render correct html, but it seems that the presence of the disabled attribute, no matter the value disables the list. So what do I tweak to the code make this work? (Preferably without using jQuery to handle the enable / disable after the event)

this might be an easy problem to solve, or not, but it's hard to explain and put into google so I couldn't find a solution.

In my database I have multiple rows and column with different data and a few have the same date, so I want to do a foreach loop that reads all the data from a single date, sums that all up and puts it into a variable, (this part I know how to do), but after all this is done in one loop, on the next loop around I want it to be the next day.

I'm wondering if this is possible? I guess you could do a i++ kind of thing but that wouldn't work when going from the 31st to 1st the next month I guess.

Does anyone know of a solution to this problem?

I'm working on project and after i select data from the database and put it into sqldatareader and trying to post it in some labels i figured that all of the labels print the same value because the sqldatareader has only one column with many values how can i print those values ??

i have a problem .i want too get the IP and name of the PC in which the staff logged in(the staff can logging through any system in the office )and i want to set alarm for the particular PC. i want the c# code for my hospital management system. please help me

I have 2 type notifications for users. I want to post all of them in same page. I need 2 repeater for different data and different styles. But there is a problem; notifications must be shown depends on date. (Both data source have SDATE column) I mean, i need date sorting for them. So how can i do that? Any advice? *I'm posting an image for explain my problem, please check it out. Thank you. ProblemExp.

I have a string which looks something like this:

some text [different text]

Using C# is it possible to insert some html tags so that resulting string would be

some text [<b>different text</b>]

It would have to cope with instances where there are no square brackets?

Thanks.

I downloaded a working MVC project to learn the actual MVC coding. On direct build, it gave me errors, I searched the net and as per suggestions I updated all the nuget packages and the other updates available. Now Razor is updated to 3.0, MVC to 5.2.3.0, Visual Studio to its latest version of VS 2012, and there is no intellisense anywhere on my project. I tried updating the web config with various values as suggested by users. I also tried updating the GUID. I created a fresh MVC 4 project and tried multiple times, but ended up updating the files and eventually back to Step 1. Its a hair pulling story now, as i cannot manage to get intellisense and all my work is stalled. Please help

I'm working for a telecommunication company and I was told to re program an existing SMS Gateway which is written in Java Spring,JMS.That program has some drawbacks in database structure and workflow and I have to restructure the process and program it in C# instead of Java.Can I know the steps I must follow and what kind of technologies must be used to create a SMS Gateway from scratch.

  1. A .net program is implemented to handle API requests and it stores data to OUTBOX table.(receiver number, message text etc.)

  2. Then Java spring program is running as a service and send the outbox messages to receivers using a business logic. But when We send bulk messages there is a 2 minutes delay.

I have an application in which an user can edit a form. This is my code :

Controller and ViewModel :

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Edit(MyGlobalObject MyGlobalObject)
    {
        MyGlobalObject.Save();
        return View();
    }
}

public class MyGlobalObject
{
    public MyObjectToEdit MyObjectToEdit { get; set; }        
}

public  class MyObjectToEdit
{
    public int MyProperty { get; set; }

    public string MyProperty1 { get; set; }

    public bool MyProperty2 { get; set; }
}

My razor view :

@model TestAppliWeb.Controllers.MyGlobalObject

@using (Html.BeginForm("Edit", "HomeController"))
{
    @Html.AntiForgeryToken()
    @Html.EditorFor(m => m.MyObjectToEdit)
}

Everything is working well. But I would like to bring a new feature to this form, depending a certain condition, itself depending of MyProperty2 of MyObjectToEdit, I would like to continue to display the form but disabled it : all the form must be displayed to the user but he cannot edit anything and click on save.

If MyProperty2 is true, the form continue to be editable, if not, the form must be disabled. But I don't know how to impact it with a minimal of code in my razor view the rendering of the form. I have a solution, but it seems too "unclean" : I disabled all the elements of the form with javascript and css.

Is there any mvc html helper or anything like this to write in the razor view to disable the form.

Thanks in advance for your help

I'm having this error and scavenged S.O. for answers. I used the [childonly], added the controller to my renderaction. I was able to submit but once I added validationmessagefor. This exception came up.

Here's the partial View


<div class="panel panel-default">
    <div class="panel-heading">
        <h4 class="panel-title">
            <a data-toggle="collapse" data-parent="#accordion" href="#Draft">
                My Drafts
            </a>
        </h4>
    </div>
    <div id="Draft" class="panel-collapse collapse">
        <div class="panel-body">

            @{
                Html.RenderAction("GetDrafts","MyPostController");
            }

        </div>
    </div>
</div>
      <div class="row">
                <div class="col-md-5">
                    <label>Reply To:<small>(optional)</small></label>
                </div>
                <div class="col-md-7"> 
                    @Html.TextBoxFor(m => m.ReplyTo,null,new { @class = "form-control" })
                    @Html.ValidationMessageFor(m => m.ReplyTo)

                </div>


            </div>

on top of that there's a

 @using (Html.BeginForm())
  {

   @Html.AntiForgeryToken()

 <div class="col-md-3">
    @*//side menu here*@
    @Html.Partial("_SideMenu", Model) 

</div>

here's the action

    /// <summary>
    /// get all saved drafts
    /// </summary>
    /// <returns></returns>
    [ChildActionOnly]
    public ActionResult GetDrafts()
    {
        var drafts = _dbrepo.GetUserDrafts();
        return PartialView("_DraftView", drafts);
    }

So as I have mentioned. I was able to post data if modelstate isvalid. but once it is invalid. that exception comes up. I tried commenting the renderaction for testing. and I was able to throw the validationmessage.

I am working on a web-forms based project in asp.net 4.6 and using bootstrap3. I want to show all asp: drop-down items in bold.

I have form-control class applied to asp:drop down list

I have registered my APP on Instagram and i Successfully retrieved recent media using: https://api.instagram.com/v1/users/self/media/recent/?access_token=ACCESS-TOKEN

Now I want to Subscribe user to instgram to get real time update , i tried this :

        $.ajax({                                                                   
            url: "https://api.instagram.com/v1/subscriptions/?client_id=MyClientID&client_secret=MyClientSecret&object=user&aspect=media&verify_token=MyToken&callback_url=MyService.ashx",
            type: 'POST',
            dataType: "jsonp",
            success: function (data) {
                console.log(data);
            },
            error: function (errorText) {
                console.log(errorText);
            }
        });

    });

the Post request above prints : {"meta": {"code": 200}, "data": []} which means it is a successful request

but i didn't receive any request from Instagram on my callback URL to send me the [ hub.challenge ]

Instagram subscription API :

Create a Subscription

To create a subscription, you make a POST request to the subscriptions endpoint.

enter image description here

Where I went Wrong ??

I have a web service written in Dotnet which returns a byte array that the web browser figures out is Excel and lets it be opened.
That is happy path.

But what if I get an error? then I'd like to return an error of some kind, let's say a human readable string.
I could return a different Excel document, one with error message, but would prefer to show it directly in the browser.

Is it even possible?
If so, how would this be implemented on the server and client?

I am using the default Web API of ASP.NET with Swagger to build and Restful API. What I am trying to do is to make it more accesible for older programs that only know Soap & Json.

I would like them to be able to send an email using a json, for example:

{"fulltemplate": "Default", "to":"info@google.com", "tags": { "Naam", "Googlemailer", "Url": "http://google.com" } }

The email should than automaticly be mapped to the right format (picked from database using the Fulltemplate variable. After that we will replace all strings in the emails that have [Key] with [value] so that we can dynamicly build emails.

I have been able to succesfully map fulltemplate and to into a variable, but the json object inside it named tags didn't work, I hoped it could automaticly map to a IDictionary<string,string> but that didn't work as intended.

I would I do such thing without having to serialize it myself in the code?

The class:

class RootObject
    {
        [JsonProperty("email")]
        public List<EmailModel> email { get; set; }
    }


    public class EmailModel
    {   
        public string fulltemplate { get; set; }    

        [JsonRequired]
        public string to { get; set; }

        public Dictionary<string, string> tags { get; set; }
    }

In old ASP.NET I could tell why my app stopped by looking at HostingEnvironment.ShutdownReason.

In ASP.NET Core, this doesn't exist. Where can I get this info?

I have done my project using ASP.Net MVC and SQL SERVER but the website which i gonna host, is not supporting SQL SERVER they asked me to change my database to MYSQL.

I used many ways, but got different run time errors.

QUESTION: HOW CAN I CHANGE MY DATABASE FROM SQL SERVER TO MYSQL?

Here is my model and context model:

namespace WebApplication11.Models
{
    [Table("Product")]
    public class ProductModel
    {
        [Key]
        [Required(ErrorMessage ="Please provide Product id",AllowEmptyStrings =false)]
        public int pid { get; set; }
        [Required(ErrorMessage = "Please provide Product Name", AllowEmptyStrings = false)]
        public string ProductName { get; set; }
        [Required(ErrorMessage = "Please Enter the Price", AllowEmptyStrings = false)]
        public decimal ProductPrice { get; set; }
        public string ProductDescription { get; set; }
        [Required(ErrorMessage = "Please Specify the Product Category", AllowEmptyStrings = false)]
        public string ProductCategory { get; set; }
        public string ProductAddress { get; set; }
        public string ProductImage1 { get; set; }
        public string ProductImage2 { get; set; }
        public string ProductImage3 { get; set; }
        [Required(ErrorMessage = "Please provide Customer ID", AllowEmptyStrings = false)]
        public int CustomerId { get; set; }
       // public DateTime ProductSubTime { get; set; }
    }

    [Table("Customer")]
    public class CustomerModel
    {
        [Key]
        public int cid { get; set; }
        [Required(ErrorMessage = "Please Enter Customer name", AllowEmptyStrings = false)]
        public string CustomerFullName { get; set; }
        [Required(ErrorMessage = "Please provide Contact Number", AllowEmptyStrings = false)]
        public int CustomerContact { get; set; }
        public string CustomerEmail { get; set; }
        [Required(ErrorMessage = "Please select Gender", AllowEmptyStrings = false)]
        public string CustomerGender { get; set; }
        public string CustomerAddress { get; set; }
    }


    [Table("adminlogin")]
    public class adminlogin
    {
        [Key]

        public string id { get; set; }
       public string name { get; set; }
        [Required(ErrorMessage = "Please Specify your name", AllowEmptyStrings = false)]
        public string username { get; set; }
        public string pass { get; set; }
        public string designation { get; set; }
    }

    [Table("contact")]
    public class contact
    {
        [Key]
        [Required(ErrorMessage = "Please Specify your name", AllowEmptyStrings = false)]
        public string Name { get; set; }
        [Required(ErrorMessage = "Please enter your contact", AllowEmptyStrings = false)]
        public string phone { get; set; }
        [Required(ErrorMessage = "Please Specify Email", AllowEmptyStrings = false)]
        public string email { get; set; }
        [Required(ErrorMessage = "Please Enter sugestion ", AllowEmptyStrings = false)]
        public string description { get; set; }
    }

    [Table("Category")]
    public class itemcategory
    {
        [Key]
        public string id { get; set; }
        public string Category { get; set; }

    }

    public class ContextModel :DbContext
    {
        public DbSet<ProductModel> Products { get; set; }
        public DbSet<CustomerModel> Customers { get; set; }
        public DbSet<itemcategory> itemCat { get; set; }
        public System.Data.Entity.DbSet<WebApplication11.Models.adminlogin> adminlogins { get; set; }

        public System.Data.Entity.DbSet<WebApplication11.Models.contact> contacts { get; set; }
    }

My connection string

<connectionStrings>
    <add name="ContextModel" 
         connectionString="Data Source=noori\sqlexpress;Initial Catalog=salesWebsiteDB;Integrated Security=True"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

And my homepage controller

public ActionResult Index()

{
    var bike = cm.Products.Where(p => p.ProductCategory == "Bike").ToList();
    var mobile = cm.Products.Where(p => p.ProductCategory == "Mobile").ToList();
    var others = cm.Products.Where(p => p.ProductCategory != "Cars" && p.ProductCategory!= "Mobile").ToList();

    ViewBag.bike = bike.ToList();
    ViewBag.mobile = mobile.ToList();
   ViewBag.others = others.ToList();


    return View(cm.Products.ToList());
}

What is the best way to Send back an image ID to a view Setting it to a HiddenFor, I want to save an image file before I save a center to which the image belongs 2.

Here is the controller code.

[HttpPost]
public ActionResult ImageUpload(IEnumerable<HttpPostedFileBase> files)
{
    Center ins = new Models.Maintenance.Center();
    ExamPortalCore.Models.Common.RenderImage Service = new 
    Models.Common.RenderImage();
    ins.CenterLogo = Service.UploadImageToDB(files);
    ImageRepository ImgRep = new ImageRepository();
    ins.Image = ImgRep.GetImageByID(ins.CenterLogo);
    CreateEditCenter(ins.CenterLogo);
    byte[] byteArray = { };
    byteArray = ins.Image.ImageBytes;
    if (byteArray != null)
    {
        return Json(new { base64imgage = Convert.ToBase64String(byteArray) }, JsonRequestBehavior.AllowGet);
    }
    else
    {
        return null;
    }
    return View();
}

The View Code:

<head>
    <meta name="viewport" content="width=device-width" />
    <title>Center</title>
</head>

<body>

@using (Html.BeginForm("Create", "Center", FormMethod.Post))
{

    @Html.AntiForgeryToken()
    <h3>Upload School Image</h3>

    <img id="ItemPreview" src="" />

    <div class="demo-section k-content wide">
        <div class="wrapper">
            <div id="products"></div>
            <div class="dropZoneElement">
                <div class="textWrapper">
                    <p><span>+</span>Add Image</p>
                    <p class="dropImageHereText">Drop image here to upload</p>
                </div>
            </div>
        </div>
    </div>


    @(Html.Kendo().Upload()
    .Name("files")
    .Async(a => a
        .Save("ImageUpload", "Center", FormMethod.Post)
        .Remove("Remove", "Center")
        .AutoUpload(true)
    )
    .Events(e => e.Success("onSuccess"))
    .ShowFileList(false)
    .DropZone(".dropZoneElement")
    .Validation(validation =>
    {
        validation.AllowedExtensions(new string[] { ".jpg", ".jpeg", ".png", ".bmp", ".gif" });
        validation.MinFileSize(500);
    })
    )

    <script>

        function onSuccess(e) {
            if (e.operation == "upload") {
                for (var i = 0; i < e.files.length; i++) {
                    var file = e.files[i].rawFile;

                    if (file) {
                        var reader = new FileReader();

                        reader.onloadend = function () {
                            $("<div class='product'><img src=" + this.result + " /></div>").appendTo($("#products"));
                        };

                        reader.readAsDataURL(file);
                    }
                }
            }
        }
    </script>



    <div class="col-lg-12">

        <div class="form-group">

            <h3>School Information</h3>
            <div class="col-md-10">
                @Html.LabelFor(model => model.CenterName, htmlAttributes: new { @class = "control-label col-md-2" })
                @Html.Kendo().TextBoxFor(model => model.CenterName)
                @Html.ValidationMessageFor(model => model.CenterName, "", new { @class = "text-danger" })
            </div>
            <div class="col-md-10">
                @Html.LabelFor(model => model.CenterURL, htmlAttributes: new { @class = "control-label col-md-2" })
                @Html.Kendo().TextBoxFor(model => model.CenterURL)
                @Html.ValidationMessageFor(model => model.CenterURL, "", new { @class = "text-danger" })
            </div>

        </div>
    </div>
    <hr />



    @Html.HiddenFor(model => model.CenterLogo,new { @Value= ViewBag.CenterLogo})
    <p>
        <input type="submit" value="Save" />
    </p>

}

I save the image before i save the center and i need to save the id of the image back to a model.

I have a page on a ASP.NET site which uses Bootstrap (v3.3.6). I am using Razor syntax to place a dropdown select input on the page, the issue I'm having is that the width of the boxes appears to be set by the length of the options within. I'd like instead to have all these dropdowns the same width. I understand I may be able to specify a specific or min/max width in CSS to resolve this but was wondering if there is any combination of the Bootstrap classes that could achieve this in a more dynamic manner?

<div class="container-fluid">
        <div class="form-group">
            <div class="col-lg-6 col-md-6 col-sm-12">
                @Html.LabelFor(model => model.AssigneeTeam, htmlAttributes: new { @class = "control-label col-md-5 col-sm-12 text-left" })
                <div class="col-md-6 col-md-offset-1 col-sm-12">
                    @Html.DropDownListFor(model => model.AssigneeTeam,
     EnumHelper.GetSelectList(typeof(WebApplication1.Models.RequestBase.AssigneeTeams)),
 new { htmlAttributes = new { @class = "form-control input-sm" } })
                    @Html.ValidationMessageFor(model => model.AssigneeTeam, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="col-lg-6 col-md-6 col-sm-12">
                @Html.LabelFor(model => model.Priority, htmlAttributes: new { @class = "control-label col-md-5 col-sm-12 text-left" })
                <div class="col-md-6 col-md-offset-1 col-sm-12">
                    @Html.DropDownListFor(model => model.Level,
     EnumHelper.GetSelectList(typeof(WebApplication1.Models.RequestBase.PriorityLevels)),
 new { htmlAttributes = new { @class = "form-control input-sm" } })
                    @Html.ValidationMessageFor(model => model.Priority, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="col-lg-6 col-md-6 col-sm-12">
                @Html.LabelFor(model => model.AffectedComponent, htmlAttributes: new { @class = "control-label col-md-5 col-sm-12 text-left" })
                <div class="col-md-6 col-md-offset-1 col-sm-12">
                    @Html.DropDownListFor(model => model.AffectedComponent,         EnumHelper.GetSelectList(typeof(WebApplication1.Models.RequestBase.EstateComponents)), new { htmlAttributes = new { @class = "form-control input-sm" } })
                    @Html.ValidationMessageFor(model => model.AffectedComponent, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="col-lg-6 col-md-6 col-sm-12">
                @Html.LabelFor(model => model.Type, htmlAttributes: new { @class = "control-label col-md-5 col-sm-12 text-left" })
                <div class="col-md-6 col-md-offset-1 col-sm-12">
                    @Html.DropDownListFor(model => model.Type,
     EnumHelper.GetSelectList(typeof(WebApplication1.Models.RequestBase.ChangeType)),new { htmlAttributes = new { @class = "form-control input-sm" } })
                    @Html.ValidationMessageFor(model => model.Type, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>
    </div>
</div>

This is a screenshot of the result, as you can see the dropdowns vary in width

for (int i = 0; i < xxx.Models.cbsearchmodel.searchvars.loopnum; i++)
{
    @using (Html.BeginForm("cbtView", "cb"))
    {
        <fieldset>
            <div class="container center-block" style="background-color: #000000;margin-top: 15px;color: #ffffff;box-shadow: 2px 2px 1px #ffd800;   border: 1px solid #ffd800;">
                <h3></h3>
                <p></p>
                <p></p>
                <p></p>
                <input type="submit" />
            </div>
         </fieldset>
    }
}

When button on this page is clicked the integer loopnum gets value and loops through the code, however when I do it again it does not clear the current values and simply adds more code. I can not find anything close to solution of this problem, is there any way at all I can fix this?

In MVC Core View, I am trying to display the Date Modified instead of Date Created if it is not empty.

So, I wrote like the following

@Html.DisplayFor(modelItem => (item.DateModified.HasValue ? item.DateModified : item.DateCreated))

But got an error saying that

Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions

So, instead of that I changed it to the following and it works.

@(item.DateModified.HasValue ? item.DateModified.Value.ToString("dd/MM/yyyy") : item.DateCreated.ToString("dd/MM/yyyy"))

However, the problem is that I have to re-specify the format of the date which I already did in Model Declaration. If not, it's showing data in dd/MM/yyyy HH:mm:ss format because I am not using DisplayFor anymore.

Another possibility is that I could use the ViewModel and add a new property to handle this kind of special text.

May I know if there is a better way to handle this kind of scenario?