Как установить постоянное десятичное значение

Дайте Вашим кнопкам отправки имя, и затем осмотрите отправленное значение в своем методе контроллера:

<% Html.BeginForm("MyAction", "MyController", FormMethod.Post); %>
<input type="submit" name="submitButton" value="Send" />
<input type="submit" name="submitButton" value="Cancel" />
<% Html.EndForm(); %>

регистрация на

public class MyController : Controller {
    public ActionResult MyAction(string submitButton) {
        switch(submitButton) {
            case "Send":
                // delegate sending to another controller action
                return(Send());
            case "Cancel":
                // call another action to perform the cancellation
                return(Cancel());
            default:
                // If they've submitted the form without a submitButton, 
                // just return the view again.
                return(View());
        }
    }

    private ActionResult Cancel() {
        // process the cancellation request here.
        return(View("Cancelled"));
    }

    private ActionResult Send() {
        // perform the actual send operation here.
        return(View("SendConfirmed"));
    }

}

РЕДАКТИРОВАНИЕ:

Для расширения этого подхода для работы с локализованными сайтами изолируйте сообщения где-то в другом месте (например, компиляция файла ресурсов к классу ресурса со строгим контролем типов)

Тогда изменяют код, таким образом, это работает как:

<% Html.BeginForm("MyAction", "MyController", FormMethod.Post); %>
<input type="submit" name="submitButton" value="<%= Html.Encode(Resources.Messages.Send)%>" />
<input type="submit" name="submitButton" value="<%=Html.Encode(Resources.Messages.Cancel)%>" />
<% Html.EndForm(); %>

и Ваш контроллер должен быть похожим на это:

// Note that the localized resources aren't constants, so 
// we can't use a switch statement.

if (submitButton == Resources.Messages.Send) { 
    // delegate sending to another controller action
    return(Send());

} else if (submitButton == Resources.Messages.Cancel) {
     // call another action to perform the cancellation
     return(Cancel());
}
20
задан Andrew Hare 6 August 2009 в 00:36
поделиться

3 ответа

Просто введите 440 и опустите букву «М». Я не получаю ошибок компиляции, и эта программа работает, как ожидалось:

namespace WindowsApplication5
{
    public partial class Form1 : Form
    {
        public Form1( )
        {
            InitializeComponent( );
            AttributeCollection attributes = 
                TypeDescriptor.GetProperties( mTextBox1 )[ "Foo" ].Attributes;           
            DefaultValueAttribute myAttribute =
               ( DefaultValueAttribute ) attributes[ typeof( DefaultValueAttribute ) ];

            // prints "440.1"
            MessageBox.Show( "The default value is: " + myAttribute.Value.ToString( ) );
        }
    }

    class mTextBox : TextBox
    {
        private decimal foo;       
        [System.ComponentModel.DefaultValue( 440.1 )]
        public decimal Foo
        {
            get { return foo; }
            set { foo = value; }
        }
    }
}
1
ответ дан 30 November 2019 в 01:11
поделиться

Я наконец выяснил, что я ввожу «440» вместо 440м или 440. Он скомпилирован и работает хорошо

11
ответ дан 30 November 2019 в 01:11
поделиться

Вы должны поместить 440 в кавычки, например:

[ConfigurationProperty("paymentInAdvanceAmount", DefaultValue = "440")]
3
ответ дан 30 November 2019 в 01:11
поделиться
Другие вопросы по тегам:

Похожие вопросы: