I have this:
[code]
public static IEnumerable
{
var janFirst = new DateTime(DateTime.Today.Year, 1, 1);
//beware different cultures.
var firstWeek = janFirst.AddDays(1 - (int)(janFirst.DayOfWeek));
int j = -1;
foreach (var weekNumber in Enumerable.Range(0, 52).Select(i => new
{
weekStart = firstWeek.AddDays(i * 7),
//Tuesday = firstWeek.AddDays(i * 3)
}).TakeWhile(x => x.weekStart.Year <= janFirst.Year).Select(x => new
{
x.weekStart,
weekFinish = x.weekStart.AddDays(6)
}).SkipWhile(x => x.weekFinish < janFirst.AddDays(1)))
{
j++;
yield return new SelectListItem
{
Value = string.Join(",",new string[]
{
weekNumber.weekStart.ToShortDateString(),
weekNumber.weekStart.AddDays(1).ToShortDateString(),
weekNumber.weekStart.AddDays(2).ToShortDateString(),
weekNumber.weekStart.AddDays(3).ToShortDateString(),
weekNumber.weekStart.AddDays(4).ToShortDateString(),
weekNumber.weekStart.AddDays(5).ToShortDateString(),
weekNumber.weekStart.AddDays(6).ToShortDateString(),
}),
Text = (j + 1).ToString(CultureInfo.InvariantCulture)
};
}
}//end method
[/code]
and for the view:
[code]
@Html.Label("txtBox", Model.Monday.ToLongDateString())
@Html.ValidationMessageFor(model => model.Monday)
[/code]
and the JQuery:
[code]
function Selectedchange() {
$("#txtBox").val($("#weekId").val().toString().split(",") [0]);
}
[/code]
but the selected value doesnt change in the label.
But If I do a textBox, like this:
[code]
Jignesh TrivediPosted May 29, 2012, 12:28 AM
Internally Html.Label is generate "for" tag, so i thing you can not change value of label.
but do one thing create you own extension of label.
like
public static MvcHtmlString MyLabel(this HtmlHelper helper, string name,string value)
{
return MvcHtmlString.Create(string.Format(CultureInfo.InvariantCulture, "", name, value));
}
Also change jQuery..
$("#txtBox").html($("#weekId").val().toString().split(",") [0]);
hope this will help u.
Jignesh TrivediPosted May 29, 2012, 7:17 AM
sure..
also provide threadID of your que..
Example:
http://www.c-sharpcorner.com/Forums/AddPost.aspx?EditThreadID=174104
If this post is really help then mark as answer.
thx.
albert albertPosted May 29, 2012, 7:09 AM
it is working.
Can u also help me a little with a other problem
Because I have some problems with saving the data.
But I post other treat oke.